找出是否有额外的字符串 [英] Find whether a extra string is there or not
本文介绍了找出是否有额外的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个字符串
例如:Var_str
我需要检查字符串是否仅包含Var_Str,或者是否附加更多字符串
,例如Var_str_Value或Var_str_Var_Variable或Var_str.Comment。 ..
请帮忙。
[edit]拼写[/ edit]
Hi, suppose I have a string
as e.g: "Var_str"
I need to check whether the string contains only "Var_Str" or it is appended by some more string
for example "Var_str_Value" or "Var_str_Var_Variable" or "Var_str.Comment"...
Please help on this.
[edit]spelling[/edit]
推荐答案
if (myStringVariable.StartsWith("Var_str") && !myStringVariable.Equals("Var_str"))
{
//There is something more to be seen
}
您可以尝试此代码。如果返回true,则没有额外的字符串。这里str是一个变量,它有一个需要验证的字符串。
You can try this code. If this returns true then there are no extra string. Here str is a varible which has a string that needs to be verified.
str.Replace("Var_str",string.Empty)==string.Empty
试试这个
Try this
const string s = "Var_str_Value";
var result = s.Replace("Var_str","");
if(result.Trim().Length>0)
{
//Contain more than characters
}
希望这有助于
Hope this helps
这篇关于找出是否有额外的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文