从字符串的一部分中删除空格
本文关键字:删除 空格 一部分 字符串 | 更新日期: 2023-09-27 18:33:49
我有文字:
SMS 'r'n't• Map - locations of
如何删除 • 和第一个后续字符之间的所有空格?
上面的例子应该导致
SMS 'r'n't•Map - locations of
通过使用正则表达式,可以像这样完成:
var input = "SMS 'r'n't• Map - locations of";
var regexPattern = @"(?<=•)'s+(?='w)";
var cleanedInput = Regex.Replace(input, regexPattern, String.Empty);
这将用空字符串替换 • 和第一个单词字符之间的任何空格。
string s = "SMS 'r'n't• Map - locations of";
string[] temp = s.Split('•');
s = temp[0]+temp[1].TrimStart(' ');
您可以使用
此正则表达式:
string toInsertBetween = string.Empty;
string toReplace = "SMS 'r'n't• Map - locations of";
string res = Regex.Replace(toReplace, "•[ ]+([^ ])", "•" + toInsertBetween + "$1");