字符串分割算法
本文关键字:算法 分割 字符串 | 更新日期: 2023-09-27 17:49:43
我有一个字符串。我想用给定的字符串数组把这个句子分成更小的字符串。
例如:输入字符串是"Word1 Word2 Word3 Word4 Word5 Word6 Word7 Word8"
,我想分割它,不包含["word2, word7, word4"]
输出类似于
"word1"
"word3"
"word5 word6"
"word8"
使用字符串。Split Method (String[], StringSplitOptions) Method .
var inputString = "Word1 Word2 Word3 Word4 Word5 Word6 Word7 Word8" ;
var separators = new []{"word2", "word7, "word4"};
var output = inputString.Split(seperators,StringSplitOptions.None);