Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Parse A Word From A String
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01283001
Message ID:
01283051
Views:
14
You can also use Convert as:
int intNumber = Convert.ToInt32( strNumber );
>Thank you. Perfect!
>
>
>
>>>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?
>>
>>Depending on what the string can look like, this may work:
>>
>>
>>string s = "+OK 1 2729"
>>string num = s.Substring(4, s.IndexOf(" ", 4) - 3);
>>int result;
>>int.TryParse(num, out result);
>>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform