如何从以下输入中获取消息
输入由字段名称格式化,用逗号分隔,后跟冒号,空格,然后是错误消息。
<FieldName1>, <FieldName2>, <FieldName3>: <ErrorMessage>"
输入示例
"ConsumerSecret, ConsumerKey: Invalid application credentials"
"Password: Invalid Must contain at least one alpha, one numeric, and one special character"
方法
string Message GetErrorByField (string FieldName, string InputString);
ErrorMessage = GetErrorByField("ConsumerSecret", "ConsumerSecret, ConsumerKey: Invalid application credentials");
ErrorMessage现在应该等于
"Invalid application credentials".
ErrorMessage = GetErrorByField("ConsumerKey", "ConsumerSecret, ConsumerKey: Invalid application credentials");
ErrorMessage现在应该等于
"Invalid application credentials".
ErrorMessage = GetErrorByField("Password", "Password: Invalid Must contain at least one alpha, one numeric, and one special character");
ErrorMessage现在应该等于
"Invalid Must contain at least one alpha, one numeric, and one special character".
答案 0 :(得分:3)
将InputString
方法中的GetErrorByField()
即第二个参数拆分为:
,然后通过考虑索引为1的拆分字符串得到结果
string Message = InputString.Split(':')[1].Trim();