【发布时间】:2015-11-18 23:14:50
【问题描述】:
我有这个字符串来自带有 ID/Passport 阅读器的虚拟串行端口:
b\0OU0IDBGR9247884874
我已将“/r”替换为“|”字符。
我想解决的问题总是在到达字符串中的第一个字符组合之前删除字符,这可能是: "ID","I
这是现阶段的问题,我尝试了以下方法来删除字符,但没有成功:
public static string RemoveSpecialCharacters(string str)
{
StringBuilder sb = new StringBuilder();
foreach (char c in str)
{
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == '<' )
{
sb.Append(c);
}
}
return sb.ToString();
}
【问题讨论】:
-
能否请您也显示预期的输出? (在您提供的示例输入之后)。我没有得到这部分
remove the characters before reaching the first combination of characters in the string which might be: "ID","I<","P<" & "V<" "VI"所以如果你显示预期的结果它可能会有所帮助。 -
“不要使用签名、标语或问候语。” stackoverflow.com/help/behavior
-
谢谢,我错过了!关于输出,它应该是:IDBGR9247884874
标签: c# regex string split character