C# 我解析richTextBox中的文本我如何清除;还有,从绳子上?
代码如下:C# 我解析richTextBox中的文本我如何清除;还有,从绳子上?,c#,winforms,C#,Winforms,代码如下: public static string ParseText(string text, int startPos, int endPos) { string images = ""; if (startPos >= 0 && endPos > startPos) { images = text.Substring(startPos + 1, endPos - startPos - 1); image
public static string ParseText(string text, int startPos, int endPos)
{
string images = "";
if (startPos >= 0 && endPos > startPos)
{
images = text.Substring(startPos + 1, endPos - startPos - 1);
images.Replace(',',' ');
}
return images;
}
我用这个零件清洁/移除,
和“
它更长…但在这个例子中,我想删除所有的“和,
如果我使用现在的代码,结果是:
我只得到第一个链接:
http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.cld&datum=201311221800&cultuur=en-GB&continent=europa
如果我删除这些行:
entries = images.Split(new[] { ',' });
for (var i = 0; i < entries.Length; i++)
entries[i] = entries[i].Replace("\"", "");
entries=images.Split(新[]{',});
对于(var i=0;i
然后我会看到所有的文本,除了,
和“
清洁、
和“
有什么问题
为什么它只显示第一个文本部分而不显示所有其他部分?尝试使用string.Replace()。有关详细信息,请参阅
e、 g
以下是我的作品
string ParseText(string input)
{
// Replace quotes with nothing at all...
var noQuotes = input.Replace("\"", "");
// Replace commas with, I dunno, "whatever you want"...
// If you want to just get rid of the commas, you could use "",
// or if you want a space, " "
return input.Replace("," "whatever you want");
}
C#中的字符串是不可变的
images.Replace(',', '');
…通过设计不会影响图像。您需要的是:
images = images.Replace(',', ' ');
也许你想把它们作为一个连接的字符串
var result = string.Join(Environment.NewLine, images.Split(new[] { ',' }).Select(e => e.Replace("\"", "")));
如果我正确理解你的评论
// could easily be an extension method
public static string ReplacingChars(string source, char[] toReplace, string withThis)
{
return string.Join(withThis, source.Split(toReplace, StringSplitOptions.None));
}
// usage:
images = ReplacingChars(images, new [] {',', '"'}, " ");
你应该看看。我们只得到第一个链接:你能分享使用
ParseText
返回内容的代码吗?更新了我的问题我更改了我的代码这是我现在使用的代码,但替换im使用的代码没有删除“and,charsIt应该在原来的位置留一个空格,或者“但它没有任何作用。请在这行中查找专用的CSV解析程序。您给我的上两个错误”“错误1空字符文字现在可以使用Austin,但我想为现在添加两个或三个选项。”。1.就像你现在加入的那样。2.仅删除“或仅限于此,并在那里留下空间。必须有一种方法删除此字符或任何其他字符,并留下空格。也许可以做一个小方法来替换字符。非常感谢现在我可以在加入或替换之间进行选择。谢谢。好的,我会试试,但是Jeff,然后我在form1中使用这个方法:richTextBox2.Text=Parse_Text.ParseText(richTextBox1.Text,positionToSearch,currentChar);但是现在这个方法返回的是IEnumerable而不是string,所以我在Form1Edit中对它进行了设置错误。。。positionToSearch
和currentChar
内容与实际删除字符无关,因此我在回答中没有提到它。
images = images.Replace(',', ' ');
var result = string.Join(Environment.NewLine, images.Split(new[] { ',' }).Select(e => e.Replace("\"", "")));
// could easily be an extension method
public static string ReplacingChars(string source, char[] toReplace, string withThis)
{
return string.Join(withThis, source.Split(toReplace, StringSplitOptions.None));
}
// usage:
images = ReplacingChars(images, new [] {',', '"'}, " ");