我想只检索来自给定字符串的那些不是全部CAPS且所有低位或只有第一个字母为高位的单词
例如,在下面的句子中,除了前4个单词之外都应该提取所有内容:
abcd Hello AJP
string str = "a abcd Hello AJP lbl_Description MHz AssignExistingUserOptionText _BTHAudClassDrv_KEYWORD A_dd actelisMetaLOOP AudEngineStream_BeginStreamSwitch_Enter AudEngineStream_BeginEOS Bo_th btnChange C_hange CDs CHECK_AND_CHANGE_ACCESS_MASKS checkBox1 CIMObjectPath ciscoISLvlan comboEmailAccounts D_elete CSVFS_ReFS D_HCP DADOrNUDReply DECnet IPv4 kJ kPa LAlt mL N_o tabPage11 uAPSD VLANs YCbCr"
答案 0 :(得分:1)
您可以使用Split
方法和LINQ:
var result = str.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
.Where(x => !x.All(char.IsUpper) &&
!x.All(char.IsLower) &&
!(char.IsUpper(x[0]) &&
x.Skip(1).All(char.IsLower)))
.ToArray();