Solved

How to Replace 2 words by a split ?

Posted on 2012-03-22
3
225 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

9 Experts available now in Live!

Get 1:1 Help Now