如何确定字符串中包含的第一个X字符内的具体子 [英] How to determine if string contains specific substring within the first X characters

查看:196
本文介绍了如何确定字符串中包含的第一个X字符内的具体子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查是否低​​于值1包含第一个X字符中的ABC。 ?你会如何使用if语句检查该

  VAR值1 =ddabcgghh;如果

(Value1.Contains(ABC))
{
发现= TRUE;
}



这可能是第一3,4或5个字符以内。

解决方案

或者,如果你需要设置中的值:

  =发现Value1.StartsWith(ABC)

编辑:鉴于你编辑,我会做这样的事情:

  =发现Value1.Substring(0,5)。载有(ABC)


I want to check whether Value1 below contains abc within the first X characters. How would you check this with if statement?

var Value1 = "ddabcgghh";

if (Value1.Contains("abc"))
   {
       found = true;
   }

It could be within the first 3, 4 or 5 characters.

解决方案

Or if you need to set the value of found:

found = Value1.StartsWith("abc")

Edit: Given your edit, I would do something like:

found = Value1.Substring(0, 5).Contains("abc")

这篇关于如何确定字符串中包含的第一个X字符内的具体子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆