Click here to Skip to main content
15,903,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For e.x

"The sky is blue. Winter is so cold"

So how can be the better code c# windows form, first to divide the sentence until "." and then another sentence until another "." ...

The Sky is blue
Winter is so cold

Thnx !
Posted
Comments
[no name] 17-Apr-12 8:53am    
Do we have an ETA as to when you will actually crack a book and try things out for yourself instead of repeatedly asking how to parse text?

You can use Split [^]method for this.

try this:

C#
using System;

class Program
{
    static void Main()
    {
    string s = "The sky is blue. Winter is so cold";
    //
    // Split string on dot.
   
    //
    string[] words = s.Split('.');
    foreach (string word in words)
    {
        Console.WriteLine(word);
    }
    }
}



hope it helps :)
 
Share this answer
 
v3
There are a few ways that you can do this. Some simple, some harder, and some unnecessarily overkill. The easiest way to achieve this is to use String.Split[^] to split this out.

When I first learned the syntax of .NET, I would work out what the rough area of the problem was that I was trying to accomplish, so I would say something like "I'm trying to split a string", and as I knew that string was an important class here, I would look up the documentation on the string class to see if it had anything in it that I could use. Reading it, I would see the Split method, and that would lead me to investigate whether or not this satisfied my needs.

As that .NET framework is a relatively well organised entity, this process often helped me reach the right answer with the minimum of fuss.
 
Share this answer
 

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