用C#,查找一个字符串在另一个字符串中出现的位置,如找不到返回不存在
来源:百度知道 编辑:UC知道 时间:2024/06/15 01:17:52
int i = "abcde".IndexOf("cd");
不过这段代码不安全,可能会被黑客利用
最好
string str=“cd”
if(cd.leangth<="abcde".leangth)
{
int i = "abcde".IndexOf("cd");}
int i = "abcde".IndexOf("cd");
如果i = -1, 表示没有这个东西。
否则,i等于子串的位置。
用indexof喔
using System;
using System.Collections.Generic;
using System.Text;
namespace C_Sharp
{
class Program
{
static void Main(string[] args)
{
string m_FristString= null;
string m_SecondString = null;
Console.WriteLine("enter first string:");
m_FristString = Console.ReadLine();
Console.WriteLine("enter Second string:");
m_SecondString = Console.ReadLine();
bool bCheck = checkString(m_FristString,m_SecondString);
if(bCheck)