Solved

How to Replace 2 words by a split ?

Posted on 2012-03-22
3
226 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Want to create a userform that looks like the image provided 10 44
Connection String 16 43
Error in script 11 47
Counting connections to SQL Server through C# 3 29
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now