indexof为字符串 [英] indexof for a string

查看:116
本文介绍了indexof为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备好了来自字符串的数据。我正在寻找一个看起来像这个ST qrgbfdsagb * gdnb * ygned * trehb * SE的子串。
代码似乎找到了第一个,但之后没有运气

请帮助


i am ready data from a string. I am looking for a substring that look like this ST qrgbfdsagb * gdnb * ygned * trehb * SE.
The code seems to work find for the first one but after that no luck

please help

 

/// < summary>

/// 文件中可能有多个835。因此,我们需要将文件解析为835文件

/// < / summary>

/// < param name =" File">< / param>

public void readFile( string 文件)

{

public void readFile(string File)

{

string ST = " ST" ;

string ST = "ST";

 

string SE = < span style ="font-size:x-small; color:#800000">" SE" ;

string SE = "SE";

 

My835FileClass MC;

My835FileClass MC;

 

//创建一个我们将在文件中搜索的字符串

string MyST = SegmentDelimator + ST + ElementSeparator;

string MyST = SegmentDelimator + ST + ElementSeparator;

 

string MySE = SegmentDelimator + SE + ElementSeparator;

string MySE = SegmentDelimator + SE + ElementSeparator;

 

int xxx = File.Length;

int xxx = File.Length;

 

if ((File.Contains(MyST)&& (File.Contains(MySE))))

{

if ((File.Contains(MyST) && (File.Contains(MySE))))

{

int Begin = File.IndexOf(MyST);

int Begin = File.IndexOf(MyST );

 

int End = File.IndexOf(MySE ,开始+ 1);

int End = File.IndexOf(MySE, Begin + 1 );

 

if (Begin< End)

{

if (Begin < End)

{

string My835 = File.Substring(Begin,End);

MC =

string My835 = File.Substring(Begin, End);

MC =

new < span style ="font-size:x-small; color:#008080"> My835FileClass (My835, DateTime 。现在,Filepath);

My835Array.Add(MC);

new My835FileClass(My835, DateTime.Now, Filepath);

My835Array.Add(MC);

File = File.Remove(Begin,End);

File = File.Remove(Begin , End );

int ggg = File.Length;

readFile(File);

int ggg = File.Length;

readFile(File );

}

else

{

return ;

}

return;

}

}

推荐答案

子串匹配最好用正则表达式完成。查看 Regex MatchCollection 类,这个教程


这篇关于indexof为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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