Dividing the text to the specified width

  

Here a list of three kinds

  1, String class the Substring () method to specify interception

  2, - Split specified character segmentation intercepts

  3, using - Split specified regular expression intercepts

Examples of the corresponding code

$text='_This_is the content of the text';$prefix=$text.Substring(0,5);$suffix=$text.Substring(5);$prefix,$suffix
$prefix,$suffix='CONTENT:here is text' -split ':';$prefix,$suffix
$prefix,$suffix='CONTENT:here is text' -split '(?<=^.{5})';$prefix,$suffix

The Supplement (? <= ^. [5])

  Regular expression "(? <= Xxx)" is called " backward reference " "" representative of the start of the text "^." Represents any character "{5}" define the number of times a placeholder

  So: the regular meaning of the text is separated from the first 5 characters, and returns the two parts ( provided that the text length is at least 6 characters )

Guess you like

Origin www.cnblogs.com/feiyucha/p/11099476.html