Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ! I have a string xxx1-0.1/1 yyy,ccc1,1. I used split and substring. All i want to get is the 0.1/1 only. Is there any optimize way to do this?

Thank you in advance!
Posted
Comments
PIEBALDconsult 29-Sep-13 22:13pm    
That doesn't look like a job for Split.
Have you tried a Regular Expression?
Sergey Alexandrovich Kryukov 29-Sep-13 23:16pm    
You didn't really specified your problem correctly. Giving just the example does not mean defining. You need to define the general case formally and 100% accurate (and then maybe you won't need to ask a question). The problem should be really simple, so first ask yourself: http://whathaveyoutried.com so far?
—SA

split will work..


http://msdn.microsoft.com/en-us/library/b873y76a.aspx[^]

C#
string words = "xxx1-0.1/1 yyy,ccc1,1";

string[] split = words.Split(new Char[] { '-', ' ', ',' });

foreach (string s in split)
{

    if (s.Trim() != "")
        Console.WriteLine(s);
}



regex is cooler though (in a nerdy i'm a coder sort of way)

Bryce
 
Share this answer
 
Dim s As String = "xxx1-0.1/1 yyy,ccc1,1"
Dim ans = s.Split(New Char() {"-"c, " "c})(1)
MessageBox.Show(ans)


make it a function
Private Function getMySpecialValue(input As String) As String
  Return input.Split(New Char() {"-"c, " "c})(1)
End Function
 
Share this answer
 
Comments
Uknownymous 30-Sep-13 0:04am    
its my the same post in other forum site.. thats where i get the answer.
[no name] 9-Oct-13 3:32am    
i guess it is for the question title is the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900