473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Detect spaces and substrings in some string

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!
Nov 16 '05 #1
6 1328
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" <ji****@gmail.com>
..
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!

Nov 16 '05 #2


Thank you very much!:)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
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");
}}
//
Nov 16 '05 #4
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#)
------------------------------------------------------------------------
Nov 16 '05 #5
Frans Bouma [C# MVP] <pe******************@xs4all.nl> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Jon Skeet [C# MVP] wrote:
Frans Bouma [C# MVP] <pe******************@xs4all.nl> 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)||(!_triedInSnippetCom pilerFirst));

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#)
------------------------------------------------------------------------
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: afrinspray | last post by:
I'm writing a function that parses a nested list string that might look like this: ( "HELLO WORLD!" 1231231 awesome ( 1 2 ) ) I wrote the logic already and it starts by splitting the string by...
1
by: Leandro Pardini | last post by:
Hello there, I'm trying to process a binary file and I really don't know how. The story: gPhoto2 downloads the images from my camera just fine, but small areas of 10x3 pixels are screwed up. I...
4
by: spam | last post by:
Is there a well-known algorithm for replacing many substrings in a string? For example, I'd like to take the string "abc def ghi jkl mno pqr" and replace, say, every instance of "abc", "ghi", and...
9
by: C3 | last post by:
I have to process some data in C that is given to me as a char * array. I have a fairly large number of substrings (well, they're not actually printable, but let's treat them as strings) that I...
8
by: Amit Khemka | last post by:
Hello All, say you have some string: ", foobar " Now i want to extract all substrings for which "isinstance(eval(substr), list)" is "True" . now one way is to walk through the whole sample...
4
by: Robert Dodier | last post by:
Hello all, I'm trying to find substrings that look like 'FOO blah blah blah' in a string. For example give 'blah FOO blah1a blah1b FOO blah2 FOO blah3a blah3b blah3b' I want to get three...
8
by: girish | last post by:
Hi, I want to generate all non-empty substrings of a string of length >=2. Also, each substring is to be paired with 'string - substring' part and vice versa. Thus, gives me , , , , , ] etc....
7
by: Peter | last post by:
Hello I have an UTF string, how can i detect what language it is? thanks from Peter (cmk128@hotmail.com)
2
by: Pilcrow | last post by:
This problem was raised in comp.lang.perl.misc, and the poster was concerned, among other things, by the speed of execution. Since C is faster than perl, I wonder how a C coder would solve it? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.