Click here to Skip to main content
15,913,939 members
Home / Discussions / C#
   

C#

 
GeneralRe: Weird behaviour Pin
Mustafa Ismail Mustafa23-Mar-09 5:26
Mustafa Ismail Mustafa23-Mar-09 5:26 
GeneralRe: Weird behaviour Pin
#realJSOP23-Mar-09 9:03
professional#realJSOP23-Mar-09 9:03 
GeneralRe: Weird behaviour Pin
Mustafa Ismail Mustafa23-Mar-09 9:27
Mustafa Ismail Mustafa23-Mar-09 9:27 
QuestionHow to find multiple occurrence in a string. Pin
CodingLover22-Mar-09 23:22
CodingLover22-Mar-09 23:22 
AnswerRe: How to find multiple occurrence in a string. Pin
Spunky Coder22-Mar-09 23:34
Spunky Coder22-Mar-09 23:34 
AnswerRe: How to find multiple occurrence in a string. Pin
Luc Pattyn23-Mar-09 1:28
sitebuilderLuc Pattyn23-Mar-09 1:28 
AnswerRe: How to find multiple occurrence in a string. Pin
#realJSOP23-Mar-09 2:52
professional#realJSOP23-Mar-09 2:52 
AnswerRe: How to find multiple occurrence in a string. Pin
#realJSOP23-Mar-09 3:17
professional#realJSOP23-Mar-09 3:17 
Here's a variation of the answer I gave previously. In this example, I supply code to count instances of the exact word.

string text = "one two three one oneone, someone for";
string alphaNumbers = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
string wordToFind = "one";
bool caseSensitive = false;
int wordCount = 0;
int pos = 0;

string text2 = text;
if (!caseSensitive)
{
	text2 = text2.ToUpper();
	wordToFind = wordToFind.ToUpper();
}
while (pos >= 0)
{
	pos = text2.IndexOf(wordToFind);
	if (pos >= 0)
	{
		wordCount++;
		text2 = text2.Substring(pos + wordToFind.Length);
	}
}

// now count only instances of the exact word
wordCount = 0;
text2 = text;
if (!caseSensitive)
{
	text2 = text2.ToUpper();
	wordToFind = wordToFind.ToUpper();
}
string[] parts = text2.Split(' ');
foreach (string part in parts)
{
	if (part == wordToFind)
	{
		wordCount++;
	}
	else
	{
		char lastChar = part[part.Length - 1];
		if ((part.Length == wordToFind.Length + 1) && (alphaNumbers.IndexOf(lastChar) == -1)) 
		{
			wordCount++;
		}
	}
}



"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


QuestionNBIS biometric image software Pin
RogerLum22-Mar-09 22:32
RogerLum22-Mar-09 22:32 
AnswerRe: NBIS biometric image software Pin
Christian Graus22-Mar-09 23:14
protectorChristian Graus22-Mar-09 23:14 
GeneralRe: NBIS biometric image software Pin
Rajesh Anuhya23-Mar-09 1:55
professionalRajesh Anuhya23-Mar-09 1:55 
QuestionSerialize an Object with XmlSerializer Pin
Ido22-Mar-09 22:25
Ido22-Mar-09 22:25 
AnswerRe: Serialize an Object with XmlSerializer Pin
Spunky Coder22-Mar-09 22:43
Spunky Coder22-Mar-09 22:43 
GeneralRe: Serialize an Object with XmlSerializer Pin
Ido22-Mar-09 22:52
Ido22-Mar-09 22:52 
GeneralRe: Serialize an Object with XmlSerializer Pin
Spunky Coder22-Mar-09 23:07
Spunky Coder22-Mar-09 23:07 
QuestionHelp needed in finding control Pin
The Pod22-Mar-09 21:51
The Pod22-Mar-09 21:51 
AnswerRe: Help needed in finding control Pin
Mycroft Holmes22-Mar-09 22:38
professionalMycroft Holmes22-Mar-09 22:38 
QuestionGridview, databind retrieving value from database Pin
Julius8822-Mar-09 21:40
Julius8822-Mar-09 21:40 
AnswerRe: Gridview, databind retrieving value from database Pin
Mycroft Holmes22-Mar-09 22:43
professionalMycroft Holmes22-Mar-09 22:43 
GeneralRe: Gridview, databind retrieving value from database Pin
Julius8822-Mar-09 23:13
Julius8822-Mar-09 23:13 
Questiona href issue Pin
Julius8822-Mar-09 20:56
Julius8822-Mar-09 20:56 
AnswerRe: a href issue Pin
Ravi Mori22-Mar-09 21:16
Ravi Mori22-Mar-09 21:16 
AnswerRe: a href issue Pin
Christian Graus22-Mar-09 21:38
protectorChristian Graus22-Mar-09 21:38 
GeneralRe: a href issue Pin
Julius8822-Mar-09 23:15
Julius8822-Mar-09 23:15 
GeneralRe: a href issue Pin
benjymous22-Mar-09 23:35
benjymous22-Mar-09 23:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.