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

I want to Pull string from string in C# language, exemple :

RemoteNode     = 0
Rem Node Name  = ISP-0(ISP)
Encapsulation  = PPPoE
Multiplexing   = LLC-based
Channel active = Yes
VPI/VCI value  = 0/38
IP Routing mode= Yes
Bridge mode    = No
PPP Username   = ********
	
PPP Password   = ********
PPP Username_ext2   = 
PPP Password_ext2   = 
Service name   = 
Remote IP Addr        = 0.0.0.0
Remote IP Subnet Mask = 0.0.0.0

This text is changing and I want to pull this string

How to get this two lines :
PPP Username   = ********
	
PPP Password   = ********
from the string ?

Thank you,
Posted

1 solution

Use a regex:

C#
public static Regex regex = new Regex(@"PPP\sPassword\s+.*|PPP\sUsername\s+=.*",
    RegexOptions.CultureInvariant
    | RegexOptions.Compiled
    );

//// Capture all Matches in the InputText
MatchCollection ms = regex.Matches(InputText);


Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
Comments
André Kraak 2-Oct-11 15:19pm    
Thanks for the useful link, my 5.
OriginalGriff 2-Oct-11 15:49pm    
You're welcome - have a look at the Free Tools forum, there are a lot of good links there.
http://www.codeproject.com/Forums/1627782/Free-Tools.aspx
Member 7766180 2-Oct-11 16:49pm    
Thank you OriginalGriff for the Expresso Link. My 5!
carlos pin 2-Oct-11 17:19pm    
Thank you OriginalGriff but i can't understand your exemple, Give me an simple exemple resolved my Proble,,,
OriginalGriff 3-Oct-11 3:41am    
1) Add the regex declaration to your class.
2) Execute the regex.Matches line when you want to find the lines.
3) You then have the two lines you are looking for extracted into "ms". Since it implements ICollection you can treat it as a normal List - access elements by number, using a foreach, whatever you need to do with them...
If you aren't sure about something, Google will help, and you could learn something useful!

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