Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a value in string like
C#
string str="stat-1-1-2:ttf_3l2-1: 0:35:11:34";

I am expecting the output is "1-1-2";

Regards,
Basha
Posted
Updated 26-Nov-11 0:17am
v4
Comments
Sander Rossel 26-Nov-11 6:19am    
Is this a one time thing? Can 1-1-2 be, for example, 11-11-12 or even 1001-1001-1002? Is it fixed length? Can other variables in the string change?
inayat basha 26-Nov-11 6:21am    
ya may be change or how can i get the out put as"ttf_3l2-1"

Use the documentation[^] on MSDN to learn how to split strings and extract specific details from them. Learn it well as you will need it throughout your programming career. Don't learn it, and your career is likely to be very short.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 26-Nov-11 23:06pm    
I voted 5, but your last sentence is a great exaggeration.
--SA
Richard MacCutchan 27-Nov-11 3:20am    
last sentence is a great exaggeration
That's what worries me!
C#
string x=str.split(':')[0].tostring();
 
Share this answer
 
v2
Comments
Sander Rossel 26-Nov-11 6:43am    
This will have output stat-1-1-2, but the OP was asking for 1-1-2.
The author seems to have accepted this answer though, so I guess it's what he wanted...
JBSAHU 28-Nov-11 1:06am    
okthen you write
string x=str.split(':')[0].SubString(0,5).toString();

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