首页 > 其他 > 详细

string函数Contains()实例

时间:2017-01-25 22:57:40      阅读:210      评论:0      收藏:0      [点我收藏+]
public bool Contains(string value)
如果值参数出现在此字符串内,或者值为空字符串(“”),则为true; 否则为false
using System;

class Example
{
    public static void Main() 
    {
       string s1 = "The quick brown fox jumps over the lazy dog";
       string s2 = "fox";
       bool b = s1.Contains(s2);
       Console.WriteLine("‘{0}‘ is in the string ‘{1}‘: {2}",
                          s2, s1, b);
       if (b) {
          int index = s1.IndexOf(s2);
          if (index >= 0)
             Console.WriteLine("‘{0} begins at character position {1}",
                               s2, index + 1);
       }
    }
}
// This example display the following output:
//    ‘fox‘ is in the string ‘The quick brown fox jumps over the lazy dog‘: True
//    ‘fox begins at character position 17

 

string函数Contains()实例

原文:http://www.cnblogs.com/bingxing/p/6350209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!