我试图返回正则表达式匹配的字符串数组stringArray
以及相关的匹配match_count
string_index
和match_length
。如何在方法返回中发送多个不同数据类型的值。我已阅读Tuple但所有示例基本上都显示了多个值,但它们似乎总是整数而不是混合类型。我不能解决如何在我的例子中使用它来实现字符串数组和整数。方法,返回不同数据类型的多个值
string ptrn_coords = @"- Coordinates: \[ ([\-0-9]+), ([\-0-9]+), ([\-0-9]+) \]";
private void button3_Click(object sender, EventArgs e)
{
string[] matches;
matches = GetMatches(s, ptrn_coords);
}
private static string[] GetMatches(string input, string pattern)
{
string[] stringArray;
Match mc = Regex.Match(input, pattern);
int string_index = 0;
int match_length = 0;
int match_count = 0;
List<String> listTemp = new List<string>();
while (mc.Success)
{
match_count++;
string_index = mc.Index;
match_length = mc.Length;
listTemp.Add(mc.ToString());
//MessageBox.Show("Match Text: " + mc.ToString() + " Index: " + string_index + " Length: " + match_length + " Count: " + match_count); // Test Message
mc = mc.NextMatch();
}
stringArray = listTemp.ToArray<String>();
return stringArray;
}
真的无法理解倒票。这似乎是一个明确的问题 –