简体   繁体   English

最后从字符串中删除标点符号

[英]Remove Punctuation characters at last from a string

I have a string value and punctuation string. 我有一个字符串值和标点符号字符串。 I need to remove punctuation characters from a string value from the last till it finds the character except punctuation character. 我需要从最后一个字符串值中删除标点符号,直到找到除标点符号以外的其他字符为止。 Here is a sample string of Input value and punctuation characters to remove. 这是要删除的输入值和标点符号字符串的示例。

Sample Input String 样本输入字符串

1. The Indian economy.My suggestion.,..,... ...

2. The Indian economy.,,[], ..My suggestion.,..,... ...[]

Punctuation characters to be removed 标点符号将被删除

[,.;:]

Result String after replace 替换后的结果字符串

1. The Indian economy.My suggestion

2. The Indian economy.,,[], ..My suggestion

Any help to this will be appreciated. 任何帮助,将不胜感激。

Thanks 谢谢

使用String.TrimEnd()

string result=str.TrimEnd('.',',','[',']',' ');

Use following pattern to match trailing punctuation characters: 使用以下模式来匹配结尾的标点符号:

@"\W+$"

string str = @"1. The Indian economy.My suggestion.,..,... ...";
string replaced = Regex.Replace(str, @"\W+$", "");
Console.WriteLine(replaced); // => 1. The Indian economy.My suggestion

\\W matches non-word characters. \\W匹配非单词字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM