PC Review


Reply
Thread Tools Rate Thread

Detect spaces and substrings in some string

 
 
juli
Guest
Posts: n/a
 
      29th Dec 2004
Good evening!
I have a function that gets a string and suppose to divide it to words
(spaces between each word) and to find if there is specific word
("hello") inside this string.
Do someone know how to do it in c#? Thank you very much!
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      29th Dec 2004
Juli,

Something as this?

\\\
string str = "bla1 bla2 hello bla4";
string[] stra;
stra = str.Split(' ');
for (int i = 0; i<4; i++)
{
if (stra[i] == "hello")
{
MessageBox.Show("The " + (i+1).ToString() +
"th word is hello");
}}
//

"juli" <(E-Mail Removed)>
..
> Good evening!
> I have a function that gets a string and suppose to divide it to words
> (spaces between each word) and to find if there is specific word
> ("hello") inside this string.
> Do someone know how to do it in c#? Thank you very much!



 
Reply With Quote
 
juli jul
Guest
Posts: n/a
 
      29th Dec 2004


Thank you very much!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Dec 2004
Little correction,

I am a little bit ashamed of this one

\\\
string str = "bla1 bla2 hello bla4";
string[] stra;
stra = str.Split(' ');
for (int i = 0; i<stra.Lenght; i++)
{
if (stra[i] == "hello")
{
MessageBox.Show("The " + (i+1).ToString() +
"th word is hello");
}}
//


 
Reply With Quote
 
Frans Bouma [C# MVP]
Guest
Posts: n/a
 
      31st Dec 2004
Cor Ligthert wrote:
> Little correction,
>
> I am a little bit ashamed of this one
>
> \\\
> string str = "bla1 bla2 hello bla4";
> string[] stra;
> stra = str.Split(' ');


this doesn't work, you have to pass in an array of char:
stra = str.Split(new char[]{' '});

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      31st Dec 2004
Frans Bouma [C# MVP] <(E-Mail Removed)> wrote:
> Cor Ligthert wrote:
> > Little correction,
> >
> > I am a little bit ashamed of this one
> >
> > \\\
> > string str = "bla1 bla2 hello bla4";
> > string[] stra;
> > stra = str.Split(' ');

>
> this doesn't work, you have to pass in an array of char:
> stra = str.Split(new char[]{' '});


Yes it does work, because the Split parameter if declared with the
"params" modifier. Try it

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Frans Bouma [C# MVP]
Guest
Posts: n/a
 
      31st Dec 2004
Jon Skeet [C# MVP] wrote:
> Frans Bouma [C# MVP] <(E-Mail Removed)> wrote:
>
>>Cor Ligthert wrote:
>>
>>>Little correction,
>>>
>>>I am a little bit ashamed of this one
>>>
>>>\\\
>>>string str = "bla1 bla2 hello bla4";
>>>string[] stra;
>>>stra = str.Split(' ');

>>
>> this doesn't work, you have to pass in an array of char:
>>stra = str.Split(new char[]{' '});

>
>
> Yes it does work, because the Split parameter if declared with the
> "params" modifier. Try it


Aw sh*t, indeed... Sorry, Cor, you're right, I was wrong.

Notes to self:
bool _doNotPostToUseNet=
((_amountGlassesChampagne>0)||(!_triedInSnippetCompilerFirst));

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
detect trailing spaces in an excel document San antonio Microsoft Excel Misc 3 9th Apr 2010 11:36 PM
Find String in another string - only between spaces =?Utf-8?B?Tmly?= Microsoft Excel Worksheet Functions 9 2nd Nov 2006 11:31 AM
Is there a string function for counting occurances of substrings? Jason Barnett Microsoft VB .NET 2 28th Oct 2005 10:41 PM
String method that counts substrings =?Utf-8?B?Q29kZVJhem9y?= Microsoft C# .NET 10 9th Jun 2005 09:55 AM
Finding substrings within a string Gaston Microsoft Excel Programming 3 2nd Feb 2004 06:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.