using System.Text.RegularExpressions; string[] ParseString(string value)
{
ArrayList al = new ArrayList(); foreach (Match m in new Regex("STRING(?<Filtered>.+?)STOP", RegexOptions.Singleline | RegexOptions.IgnoreCase).Matches(value))
{
string filteredValue = m.Groups["Filtered"].Value; if (!al.Contains(filteredValue))
{
al.Add(filteredValue);
}
} if (al.Count == 0)
{
return null;
} return (string[])al.ToArray(typeof(string));
}
{
ArrayList al = new ArrayList(); foreach (Match m in new Regex("STRING(?<Filtered>.+?)STOP", RegexOptions.Singleline | RegexOptions.IgnoreCase).Matches(value))
{
string filteredValue = m.Groups["Filtered"].Value; if (!al.Contains(filteredValue))
{
al.Add(filteredValue);
}
} if (al.Count == 0)
{
return null;
} return (string[])al.ToArray(typeof(string));
}
public ArrayList GetString(string[] strArray)
{
string[] tmpStrArray = strArray;
ArrayList result = new ArrayList();
string str;
for( int i=0; i<tmpStrArray.Length; i++)
{
if( tmpStrArray[i].Substring(0,6) == "string" && // 判断前面6个
tmpStrArray[i].Substring(tmpStrArray[i].Length - 4) == "stop" ) // 判断后面4个
result.Add( tmpStrArray[i].Substring(5, tmpStrArray[i].Length - 10 ); //取中间的
}
// 再写一个判断有没有重复的,有的话就Remove这个...
return result;
}