Home > Net >  C # Regex. The Split () usage
C # Regex. The Split () usage

Time:12-14

Have so a bunch of string:
==x. administrative areas "Beijing" | | x. Administrative area=="Shanghai" | | x. Administrative area=="hebei" & amp; & X. regional city=="city" & amp; & X. water-bearing layers of a=="shallow" & amp; & X. water-bearing layers of a=="deep"
Now want to summary the words into the following:
Administrative regions: Beijing, Shanghai, hebei, Regional city: city; Depth: shallow, medium deep

There are two questions:
First, how to said above the string of a string in c #?
String Str=@ "x. Administrative area==" Beijing "| | x. Administrative area==" Shanghai "| | x. Administrative area==" hebei "& amp; & X. regional city=="city" & amp; & X. water-bearing layers of a=="shallow" & amp; & X. water-bearing layers of a=="in the deep" "is certainly not;
No way, I have to write it in a text file, and then read from a text file method;

Second, because of the separator is two characters, so can't use string. The split, so we have to use the regex. The split, but after tests found
Regex. Split (Str, @ "& amp; & amp;" This is normal, can offer three;
But the Regex. Split (item, @ "| |") how is error, points out a lot, see below


  •  Tags:  
  • C#
  • Related