Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to use a loop for, or a condition if...

ex. I have a text "Today is so hot. Tomorrow will rain. Yesterday was wet"

so using any loop (for) or condition if, how can I do that: When you find first dot(".") stop and take sentence before dot, then continue for next dot(".") again sotp and take sentence before dot... and to continue till last dot :

the output to be:

Today is so hot
------------------
Tomorrow will rain
------------------
Yesterday was wet
------------------


thnx
Posted

Did you have any problem with Split function.
You can try as
C#
string s = "Today is so hot. Tomorrow will rain. Yesterday was wet.";
           string[] words = s.Split(Convert.ToChar('.'));
            foreach (string ss in words)
           {
               Console.WriteLine(ss);

           }
           Console.ReadKey();
 
Share this answer
 
Comments
VJ Reddy 18-Apr-12 3:35am    
Good answer. 5! But I think Convert.ToChar is not required. ss.Trim() may be used to remove spaces.
uspatel 18-Apr-12 3:37am    
thanks reddy.
But he needs spaces.
VJ Reddy 18-Apr-12 3:39am    
I mean spaces in the start and end. Because in the question the three sentences are left justified. After splitting at . there will be a space before Tomorrow and Yesterday, so that the sentences will not be left justified.
Thank you.
tell me the idea u can do this like this
replace("Your Sentence ",".","")

if you want through loop

C#
for (a=0 , a<sentence.length,>{

if (sentence.index[a] !=".")
{
new_Sentence=new_sentence+sentence.index[a];
}

}


code contain syntax error . But the logic is clear
 
Share this answer
 
v2

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