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
. Then just substring to the index.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.