Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I want to get 1-2 from given string "Ver 1-2x"

How can I do?

Thanks
sjs
Posted
Updated 5-Jan-11 2:36am
v2

C#
string ver = "Ver 1-2x";
ver = ver.Substring(4, 3);
 
Share this answer
 
Comments
Hiren solanki 5-Jan-11 8:40am    
Good simplistic answer JF2015. +5
string str="Ver 1-2x";
int startind=str.indexof("1");
int endind=str.indexof("x");

string result=str.substring(startind,endind);
 
Share this answer
 
Comments
fjdiewornncalwe 5-Jan-11 11:22am    
Won't work as you have it. The second argument of .substring is length, not end index.
Sandesh M Patil 5-Jan-11 11:26am    
the second argument is length
and as i write endind=length. It finds the index of x

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