13,091,300 members (61,609 online)
Rate this:
See more:
```char[] charArray = new char[1000];
charArray = richTextBox1.Text.ToCharArray();
for (int i = 0; i < charArray.Length; i++)
{
int c = Convert.ToInt32(charArray[i]);
if(c>=48 && c<=57)

else if (Char.IsLetter(charArray[i]))
{
int c1 = Convert.ToInt32(charArray[i]);
if (c1 >= 65 && c1 <= 90 || c1 >= 97 && c1 <= 122)
}
}```

Got stack in a small problem.Try to find numbers and words from this loop.But what i do is..it prints as letter or digit for each character.But i want if i write 123.45 or write WORD in richtextbox it will show output as 123.45 is a number and WORD is a word in listview.but my loop prints as like as...
1-->number
2-->number
.
.
W-->alphabet
O-->alphabet
.
.
So how can i combine these characters as number or word?Is my checking criteria is wrong?
Posted 12-Nov-12 6:45am
ridoy59.3K
Updated 12-Nov-12 6:48am
v2

Rate this:

## Solution 4

Thanks for response.I solve it using following code..
``` while(i<chararray.length)>
{
while (Char.IsDigit(charArray[i]) || Char.IsLetter(charArray[i]))
{
word = word + charArray[i];
i++;
}

double num;

if (double.TryParse(word, out num))
{
if (charArray[i].ToString() == ".")
{
word += charArray[i];
i++;
while (Char.IsDigit(charArray[i]))
{
word += charArray[i];
i++;
}
}
}
else
{
}
word = "";
}```
Rate this:

## Solution 1

Hi,

Try this:
```string[] parts = richTextBox1.Text.Split(' '); // split the text
foreach (string part in parts)
{
double d = 0;
if (double.TryParse(part,d)) // try to parse the current part to a number
{
listView1.Items.Add(part + "-->number"); // if you can parse, add part + "-->number" to the ListView
}
else
{
listView1.Items.Add(part + "-->word"); // if you can't parse, the current part is a word, add part + "-->word" to the ListView
}
}```

Hope this helps.
ridoy 12-Nov-12 13:00pm

Thanks for your reply,but sorry i need to escape whitspace for what i can't check those characters by detecting whitespace.
Rate this:

## Solution 3

You will need to store the chars in a variable then print them when you change to the other type. Below is an example. This example doesn't check for punctuation or white space though you could easily add that.

```private void ParseThis()
{
char[] charArray = new char[1000];
charArray = richTextBox1.Text.ToCharArray();
string number = string.Empty;
string word = string.Empty;

for (int i = 0; i < charArray.Length; i++)
{
int c = Convert.ToInt32(charArray[i]);
if (c >= 48 && c <= 57)
{
if (number.Length == 0)
{
if (word.Length > 0)
word = string.Empty;
}
number += charArray[i].ToString();
}

else if (Char.IsLetter(charArray[i]))
{
int c1 = Convert.ToInt32(charArray[i]);
if (c1 >= 65 && c1 <= 90 || c1 >= 97 && c1 <= 122)
{
if (word.Length == 0)
{
if (number.Length > 0)
number = string.Empty;
}

word += charArray[i].ToString();
}
}
}

if (word.Length > 0)
if (number.Length > 0)

}```
Rate this:

## Solution 2

If I understood correctly, if input is 123.45, it should say "NUMBER" else it should say "WORD".
If this is true, why dont you try double.TryParse ? and Int.TryParse?
It will be something like

```double value;
bool isNumber = double.TryParse(richTextBox1.Text,out value);
if(isNumber)
{
}
else
{
}```

Hope that helps
Milind

Top Experts
Last 24hrsThis month
 ProgramFOX 180 OriginalGriff 150 Richard MacCutchan 55 ppolymorphe 45 Dave Kreskowiak 40
 OriginalGriff 3,612 Graeme_Grant 1,944 ProgramFOX 1,887 Jochen Arndt 1,645 ppolymorphe 1,572