Solved

How to Replace 2 words by a split ?

Posted on 2012-03-22
3
228 Views
Last Modified: 2012-03-22
Lets say I have a string:   "Hello_World"


I would like the result to be:   "World_Hello"


how can I do that?
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 500 total points
ID: 37754078
Would this need to be dynamically capable so that Hello_World could equal any size string delimited with "_"?

Spitting the string based on the "_" delimeter:

string[] splitList = "Hello_World".Split('_');

Open in new window


Re-assembling the string based on index:

string resultString = string.Format("{0}_{1}", splitList[1], splitList[0]);

Open in new window


Doing this from memory so I cant check syntax as well as usual.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37754130
Try This, a bit of linq but worthy the solution, Now your text can be dynamic:-
            string value = "Hello_World_Test_Test1_test2";
            var arrStrings = value.Split('_').Reverse().ToArray();

            Console.WriteLine(string.Join("_", arrStrings));

Open in new window

0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 37754251
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question