How to Split two strings? [Resolved]

Posted by Gudevg under C# on 4/9/2012 | Points: 10 | Views : 6362 | Status : [Member] | Replies : 20
Hi all,

In the input side, i have single document and it having a some datum.

I want to split up this datum into two strings like String A & B, The only option i have to split it with the conditional keyword called action, most probably it is the only word which correctly split the string into two.

Problem i am facing here is 1/50 document have the word like reaction, which occurs multiple times the same keyword (action) within the datum.

Since i tried to give the split keyword like " action" to avoid these but it encounter "Index was outside the bound of the array"

Did any one help me to resolve this issue?


Regards,

Deepakkumar G.


Responses

Posted by: muralikrishnasurap-12704 on: 4/9/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Please find below code

 string s = "details before reaction splitting  action details after spliting ";

string[] words = s.Split(new string[]{ " action "},StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words)
{
Console.WriteLine(word);
}
Console.Read();


Output:

details before reaction splitting
action details after spliting


Best Regards
Murali Krishna.S

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/9/2012 [Member] Bronze | Points: 25

Up
0
Down
You Can REfer

http://www.dotnetperls.com/split

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/9/2012 [Member] Silver | Points: 25

Up
0
Down
hi deepak,
use different keyword.. like "split_file_action".. these type of words may not possible to occurance in datum..

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/9/2012 [Member] Silver | Points: 25

Up
0
Down
why i told use '_' means, underscore based words comes rare case only..

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/9/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Deepak,
plz refer this link.

http://www.csharp-station.com/HowTo/StringJoinSplit.aspx

Thanks & Regards
Hari

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Deepak,

dID yOU gET rESULT

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
Yes i coded already ji, with stringvalue.split(string name[] ("condition")) & stringsplitoptions
My question is how to declare that splitter value (action)?
I want only that particular value is used to split not on the similar words like reaction.


Regards,



Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Please CheckThis

http://coders-project.blogspot.in/2010/05/split-function-in-c.html


http://www.csharp-station.com/HowTo/StringJoinSplit.aspx

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
It was working.


Thanks,

Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Deepak

Okey...

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/10/2012 [Member] Silver | Points: 25

Up
0
Down
Thanks to Murali Krishna.S

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/10/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Mr. Murali,

i hav one doubt in your coding..
input is "details before reaction splitting action details after spliting";
then expected output(only two parts) come..

but input will come more one "action"..........??????????

on that time the given input splited to more than two parts....!!!!!!!!!!!???????????????



Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: muralikrishnasurap-12704 on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,
string[] words = s.Split(new string[]{ " action "},StringSplitOptions.RemoveEmptyEntries);

the above part of code uses keyword as " action " ,action with spaces hence it will split only 2 array of string.

Best Regards
Murali Krishna.S

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

I suppose to use the same " action" for splitting the strings it ran with "Index was outside the bound of the array".


Regards,


Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: muralikrishnasurap-12704 on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Please use same part of code and let me know...what you are facing the problem..


string s = "details before reaction splitting  action details after spliting ";


string[] words = s.Split(new string[]{ " action "},StringSplitOptions.RemoveEmptyEntries);

foreach (string word in words)

{

Console.WriteLine(word);

}

Console.Read();


Best Regards
Murali Krishna.S

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/10/2012 [Member] Silver | Points: 25

Up
0
Down
ok Mr.murali...

for example,

"details before reaction splitting action details after the action spliting"

the above sentence is input means what is the output...?

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: muralikrishnasurap-12704 on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Singaravel,

Please find the out put for the string "details before reaction splitting action details after the action spliting"
string s = "details before reaction splitting action details after the action spliting";

string[] words = s.Split(new string[] { " action " }, StringSplitOptions.RemoveEmptyEntries);

foreach (string word in words)
{

Console.WriteLine(word);

}

Console.Read();


OutPut:
details before reaction splitting

details after the
spliting



Best Regards
Murali Krishna.S

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Muralikrishna.Surap@Gmail.Com
Superb

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/10/2012 [Member] Silver | Points: 25

Up
0
Down
Why i ask means...

the query is.. look the bold items below...


Hi all,

In the input side, i have single document and it having a some datum.

I want to split up this datum into two strings like String A & B, The only option i have to split it with the conditional keyword called action, most probably it is the only word which correctly split the string into two .

Problem i am facing here is 1/50 document have the word like reaction, which occurs multiple times the same keyword (action) within the datum.

Since i tried to give the split keyword like " action" to avoid these but it encounter "Index was outside the bound of the array"

Did any one help me to resolve this issue?

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/10/2012 [Member] Silver | Points: 25

Up
0
Down
Mr. Sabari magesh,

first understand the query...


Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response