[英]STRING: how to get string output from this input string?
How do you get the message from the following inputs 您如何从以下输入中获取消息
Input is formated by field name separated by comma, followed by a colon, space and then the error message. 输入的格式为字段名,以逗号分隔,后跟冒号,空格,然后显示错误消息。
<FieldName1>, <FieldName2>, <FieldName3>: <ErrorMessage>"
Input Example 输入范例
"ConsumerSecret, ConsumerKey: Invalid application credentials"
"Password: Invalid Must contain at least one alpha, one numeric, and one special character"
Method 方法
string Message GetErrorByField (string FieldName, string InputString);
ErrorMessage = GetErrorByField("ConsumerSecret", "ConsumerSecret, ConsumerKey: Invalid application credentials");
ErrorMessage should now equal 现在,ErrorMessage应该等于
"Invalid application credentials".
ErrorMessage = GetErrorByField("ConsumerKey", "ConsumerSecret, ConsumerKey: Invalid application credentials");
ErrorMessage should now equal 现在,ErrorMessage应该等于
"Invalid application credentials".
ErrorMessage = GetErrorByField("Password", "Password: Invalid Must contain at least one alpha, one numeric, and one special character");
ErrorMessage should now equal 现在,ErrorMessage应该等于
"Invalid Must contain at least one alpha, one numeric, and one special character".
通过以下方法拆分InputString
即GetErrorByField()
方法中的第二个参数:
然后,您将通过考虑索引为1的拆分字符串来获得结果
string Message = InputString.Split(':')[1].Trim();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.