Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My string is :700,236 lblVoucherNo

I want like this : 700, 236
Posted
Comments
Kornfeld Eliyahu Peter 11-Jan-16 8:27am    
It has always the form of <numeric>,<numeric>[white-space]<string>?
PIEBALDconsult 11-Jan-16 8:46am    
Regular Expressions.
^(?'first'\d+),(?'second'\d+)
Sathish km 11-Jan-16 8:46am    
Got it...

items.Split(' ')[0];
deepankarbhatnagar 12-Jan-16 0:50am    
PLease explain more of your query, what your question is?

string.Split will break a string into all the separate parts, not just the first two, but it will work as Raje_ suggests.
A better solution might be to use a Regex:
^(\w+\s+\w+)
woudl do it.
 
Share this answer
 
In addition to the Split function, if the text is long with many words it will probably be more efficient to simply find the first space using IndexOf and then using Substring to get all text up to the space.
 
Share this answer
 
Is this what you want?

C#
string strVal = "700,236 lblVoucherNo ";

       string[] newStrArr = strVal.Split(' ');

       string newStr = newStrArr[0];

       Response.Write(newStr);
 
Share this answer
 
Comments
Raje_ 12-Jan-16 1:18am    
Wow some one down voted without giving any reason... :(

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