[英]Trim string at first punctuation character excluding white space
I am looking for a way to trim a string at the first instance of a punctuation character that isn't a space. 我正在寻找一种在不是空格的标点符号的第一个实例处修剪字符串的方法。
Thanks 谢谢
[EDIT] I have tried the following: [编辑]我尝试了以下方法:
var length = input.IndexOf(@"[^\w\s]");
return input.Substring(0, length);
string s = "Hello, world!";
string t = new string(s.TakeWhile(c => !Char.IsPunctuation(c)).ToArray());
You are looking for Char.IsPunctuation
. 您正在寻找
Char.IsPunctuation
。 Then just substring to the index. 然后只是将子字符串添加到索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.