如何从文本(字符串)中提取字符串? [英] How to Pull String from Text(String) ?
本文介绍了如何从文本(字符串)中提取字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
我想从C#语言的字符串中拉出字符串,例如:
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,
推荐答案
使用正则表达式:
Use a regex:
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);
获取 Expresso [ ^ ]-它是免费的,它可以检查并生成正则表达式.
Get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.
这篇关于如何从文本(字符串)中提取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文