【发布时间】:2015-03-31 03:01:04
【问题描述】:
我有字符串:
" testfile.txt #testfile.txt
My new message
Filename1.doc #filename.doc"
如何找到以“#”开头的文件名并将其从字符串中删除
【问题讨论】:
-
你的预期输出是什么?
-
我的预期输出是:“testfile.txt 我的新消息 Filename1.doc”
-
您的输入是否包含换行符?试试
Regex.Replace(str, @"#\S+", ""); -
是的!我的输入包含换行符,它应该保留在输出中。感谢您的回复。
-
试试
Regex.Replace(str, @"#\S+", "");或Regex.Replace(str, @"#.*", "");