我的句子是:!doar 12345, rayantt
使用string.Contains(!doar),我需要获取其他值:
int mount = 12345;
string destiny = "rayannt";
答案 0 :(得分:1)
让input
成为问题中所述的输入字符串,searchString
是您要搜索的字符串; strParam
和intParam
是两个必需的输出;现在考虑以下代码:
string input = "!doar 12345, rayantt";
string searchString = "!doar";
string strParam=string.Empty ;
int intParam=0;
if (input.Contains(searchString)) // check for the existence of the search string in given string
{
input = input.Replace(searchString, ""); // remove the searchstring from the input
string[] contents = input.Split(',');
int.TryParse(contents[0], out intParam); // collect the integer param
strParam=contents[1]; // collect the string param
}
// here you get 12345 in intParam and "rayantt" in strParam