Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从字符串中删除数字_C#_Regex_Sharepoint 2010_Listitem - Fatal编程技术网

C# 从字符串中删除数字

C# 从字符串中删除数字,c#,regex,sharepoint-2010,listitem,C#,Regex,Sharepoint 2010,Listitem,当我从SharePoint 2010中列表的“作者”列中获取列表值时,将显示以下内容: 二,#SP10设置 现在创建该特定列表项的用户是“SP10Setup”,现在有没有一种简单的方法可以在不影响“SP10Setup”中的数字的情况下删除SP10Setup开头的“2;#” 我有一个方法,目前正在剥离所有数字 //method to strip out unnecessary digits public static string RemoveDigits(string key) { retur

当我从SharePoint 2010中列表的“作者”列中获取列表值时,将显示以下内容:

二,#SP10设置

现在创建该特定列表项的用户是“SP10Setup”,现在有没有一种简单的方法可以在不影响“SP10Setup”中的数字的情况下删除SP10Setup开头的“2;#”

我有一个方法,目前正在剥离所有数字

//method to strip out unnecessary digits
public static string RemoveDigits(string key)
{

return Regex.Replace(key, @"\d", "");
}
这是我获取特定列表项值的方式:

string author = listItem["Author"].ToString();
这就是我删除不需要的数字和字符的方法:

//calling the RemoveCharacter method
string noDigitsAuthor = RemoveDigits(author);
string cleanedupAuthor = noDigitsAuthor.Replace(";", "").Replace("#", "");
我从中得到的结果是“SPSetup”,但理想情况下,我希望结果是“SP10Setup”

实现这一目标的最快和最简单的方法是什么


提前感谢

使用像
^\d*这样的正则表达式#
^
匹配字符串的开头,
\d*
表示匹配零个或多个数字,
#
是文本。

使用正则表达式,如
^\d*#
^
匹配字符串的开头,
\d*
表示匹配零个或多个数字,
#是文字。

你不应该自己做。 使用类

因此,您将有:

cleanedupAuthor = "SP10Setup"
authorId = 2

你不应该自己做。 使用类

因此,您将有:

cleanedupAuthor = "SP10Setup"
authorId = 2

如果字符串的长度始终相同,则可以使用和“#”不是数字。但是你可以在al'的第一个位置获得战利品和“#”不是数字。但是你可以在

哇,这工作非常简单,不需要乱动正则表达式,也不需要替换字符。。。非常感谢,这非常简单,不需要乱搞正则表达式,也不需要替换字符。。。非常感谢