Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reverse order of string, but keep numbers intact

I have a string like this:

1.1.168.192

I need to convert it to this, with the numbers intact but the order reversed:

192.168.1.1

This seems like an easy question, but I cant figure it out. I’m trying something within a for loop right now but I don’t know how to make it work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This could help:

string[] splitted = "1.1.168.192".Split('.');
Array.Reverse(splitted);
string reversed = string.Join(".", splitted);

The idea is you can split things by using a char and it creates an array, then reverse it, and then join them by using a char again it will become string again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading