Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

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


C#
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
Comments
AnkitGoel.com 19-Dec-12 11:24am    
unable to understand what u want. can u explain?
Killzone DeathMan 19-Dec-12 11:31am    
Agree!
glennPattonWork3 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");
AnkitGoel.com 19-Dec-12 11:37am    
please elaborate by example. your input and required output.
glennPattonWork3 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!!

Use a regex - you can select based on alternatives and also on digits. For example:
\d\d/\d\d/\d{4}
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.
 
Share this answer
 
So for all the people I managed to confuse here the solution I worked out
while being bothered on the phone was-is
C#
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";
                }
        }

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

I find that the off switch works brilliantly for most phone models:
http://brokenjpg.net/wp-content/uploads/2011/04/SledgeHammer.jpeg
glennPattonWork3 20-Dec-12 3:40am    
This time I have asked questions before where Regex seems to be the answer!
Glenn

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900