我有一个包含这些内容的文本文件,
Apple 5 [KG]
橙7 [KG]
水10 [L]
我写过这个,从文本文件中获取特定位置
//a function to get a value between two different strings
public static string getBetween(string strSource, string strStart, string strEnd)
{
int Start, End;
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
else
{
return "";
}
}
我正在使用它来显示textBox中的值,(在选择文件并加载和填充之后)
textBox1.Text = getBetween(filetext, "Apple ", "[");
//filetext is a string that contains the selected file's name
如果我使用类似的方法(或更好的方法)通过编辑同一文本框中的值来替换apple的权重值,我需要做什么更改或者什么是“putBetween”的代码段“功能还是什么?