我有以下字符串:
http://www.powerwXXe.com/text1 123-456 text2 text3/
Run Code Online (Sandbox Code Playgroud)
有人可以给我关于如何获取text1,text2和text3的值并将它们放入字符串的建议.我听说过正则表达式,但不知道如何使用它们.
如果您知道字符串将始终具有相似的格式,则可以string.Split
先使用/
,然后使用空格并从结果字符串数组中检索结果,而不是使用RegEx路径.
string[] slashes = myString.Split('/');
string[] textVals = slashes[3].Split(' ');
// at this point:
// textVals[0] = "text1"
// textVals[1] = "123-456"
// textVals[2] = "text2"
// textVals[3] = "text3"
Run Code Online (Sandbox Code Playgroud)