Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Parse A Word From A String
Message
From
18/01/2008 12:24:49
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01283001
Message ID:
01283041
Views:
11
>>>I'm gonna convert it to an int.
>>>
>>>There will always be a number in this position.
>>>
>>>
>>>>>
string s = "+OK 1 2729"
>>>>>
>>>>>How do I parse the '1' from the above string?
>>>>
>>>>What do you want to do with it? Remove it? Obtain the value that is always in that space?
>>
>>I'm assuming the string will always be the same length, or at least the character in question will always be in position 5. I'll also assume the character will always been one character.
>>
>>This is in VB:
>>
>>        Dim test As String
>>        Dim result As Integer
>>
>>        test = "+OK 1 2729"
>>
>>        If Integer.TryParse(test.Substring(4, 1), result) = True Then
>>            'result now contains the integer
>>            MsgBox(result.ToString)
>>        Else
>>            'value could not be converted
>>        End If
>>
>
>Here it is in C# (same assumptions as Mike)
>
>string s = "+OK 1 2729";
>int i;
>if (int.TryParse(s.Substring(4,1))
>{
>  MessageBox.Show(string.Format("i:{0}",i));
>}
>else
>{
>  // value could not be converted
>}
>
Einar, don't you need to pass i into the TryParse method?
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform