Actually, the first character of strA and strC is a space, the first
character of strB is the character '2', not the actual integer to (it is the
character representation of 2 from the perspective of the framework).
Basically, to do what you want, I would split the string into an array
of strings using space as the delimiter (I'm assuming that's what you are
using to delimit words) and then seeing if the first element in the array is
an integer representation:
public static bool StartsWithInt(string value, out int intValue)
{
// Split the string.
string[] parts = value.Split(new char[]{ ' ' });
// If there are elements, then continue, otherwise, return
// false.
if (parts.Length = 0)
{
// No integer here.
return false;
}
// Try and parse the first element.
return Int32.TryParse(parts[0], out intValue);
}
Mind you, there is no check to see if the value parameter is null, which
you might want to do.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"seema" <se***@discussions.microsoft.comwrote in message
news:60**********************************@microsof t.com...
Hi,
I have a following strings
strA = " 1 my first work out".
strB = "2 my second work out"
strC = " My last work out"
My strA and strB first char is int and strB first char is " ". I want to
check if in a string first char returns int (1, 2 or ---) then do this
otherwise do that.
How can I know that the first char of string is returing an int or not.
Thanks