Click here to Skip to main content
12,822,379 members (44,756 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
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";

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)
Posted 19-Dec-12 6:15am
Comments 19-Dec-12 11:24am
unable to understand what u want. can u explain?
Killzone DeathMan 19-Dec-12 11:31am
glennPattonWork 19-Dec-12 11:31am
Sorry got distracted by the phone as I was typing this, The issue is I can seperate all the parts of the string apart from the time date is returned as #15:53:23 19/12/2012, using the foreach() and the if() I can seperate out the time as it starts with a '#' I get #15:53:23, the space is chopped out as delimeter I just need a way to get 19/12/2012 hence the abortive subString.StartsWith("xx/xx/xxxx"); 19-Dec-12 11:37am
please elaborate by example. your input and required output.
glennPattonWork 19-Dec-12 11:56am
I need a method of finding a the string 19/12/2012 and adding it to the rich text box, other versions of subString are found using the lead character ( a # and an E) what I was thinking of doing, again the telephone! was checking to see if the string was of the length, another blooming phone call!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use a regex - you can select based on alternatives and also on digits. For example:
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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) == "/"))
                        TextReplyTrim += subString + "\n";

Thanks listening I will look at using Regex as Original Griff keeps suggesting once I get chance to. Oh my the b******* phone!
OriginalGriff 19-Dec-12 12:18pm
I only suggested it once! :laugh:

I find that the off switch works brilliantly for most phone models:
glennPattonWork 20-Dec-12 3:40am
This time I have asked questions before where Regex seems to be the answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100