在foreach中有一种简单的方法可以做到这一点...... [英] Is there an easy way to do this in a foreach...

查看:45
本文介绍了在foreach中有一种简单的方法可以做到这一点......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试使用foreach将循环中的字符串拆分为





Hi All,

I''m trying to use a foreach to split up a string as follows with this inside the loop


if (subString.StartsWith("#")||(subString.StartsWith("E"))||(subString.StartsWith("XX/XX/XXXX")))
                TextReplyTrim += subString+"\n";





我需要的数据通常前面带有''#'',在一种情况下是''E''唯一的另一个问题是它正确追加时间的时间和日期,但没有看到时间显示的日期#15:53:23 19/12/2012这得到时间时间抓到#15:53:23这个空间然后被处理为#15:53:23日期是丢失

但是通过显示带有消息框的subString中的所有项目,它显示日期为2012年12月19日,但我似乎无法找到获取日期的方法,包括通过if()我真的需要把它作为一个字符串而不是日期时间程序分开吗?。



格伦(困惑)



The Data I need is generally preceded by a ''#'' in one case an ''E'' the only other problem issue is the time and date it appends the time correctly but does not see the date the time is presented as #15:53:23 19/12/2012 this get the time time grabbed as #15:53:23 space this then get processed as #15:53:23 the date is lost
but by showing all the items in subString with a message box it shows the date as 19/12/2012 but I can''t seem to find a way to get the date, included via the if() I really need to seperate this as a string rather than the date time routines ?.

Glenn (confused)

推荐答案

使用正则表达式 - 您可以根据备选方案和数字进行选择。例如:

Use a regex - you can select based on alternatives and also on digits. For example:
\d\d/\d\d/\d{4}

匹配19 / 12/2012和01/06/1996等

如果没有样本输入和输出,我不确定你要做什么,但如果你需要的话,可能是正则表达式进行复杂的文本比较 - 这正是它们的开发目的。



获取 Expresso [ ^ ] - 它这是免费的,它检查并生成正则表达式。

Would match 19/12/2012 and 01/06/1996 etc.
I''m not exactly sure what you are trying to do without sample input and outputs, but a regex is probably the way to go if you need to do complex text comparisons - that is exactly what they were developed for.

Get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.


所以对于所有的人我设法在这里混淆了我解决的解决方案

而被打扰在手机上是 -

So for all the people I managed to confuse here the solution I worked out
while being bothered on the phone was-is
foreach (string subString in TextReply.Split(delimiters))
        {

            if (subString.StartsWith("#") || (subString.StartsWith("E")))
            {
                TextReplyTrim += subString + "\n";
            }
            //MessageBox.Show(subString +" "+subString.Length.ToString());
                if ((subString.Length == 10))//.Substring(1, 1) == "/"))
                {
                    MessageBox.Show("Hurrzzah!");
                    TextReplyTrim += subString + "\n";
                }
        }



感谢收听我将使用Regex作为原始Griff一旦我有机会继续建议。哦,我的b *******电话!

格伦


Thanks listening I will look at using Regex as Original Griff keeps suggesting once I get chance to. Oh my the b******* phone!
Glenn


这篇关于在foreach中有一种简单的方法可以做到这一点......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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