Reverse a string and randomly change the position of character of a string using C# and VB.Net

Last Reply on Mar 03, 2017 07:12 AM By dharmendr

Posted on Mar 03, 2017 02:56 AM

Hi

 

How count array in normal and reverse and random ?

 

For example:

123456

654321

321456

456321

213456

214356

Means all the way count ?

Because i am trying to do my parameters in url

http://xyz.com?id=0&name=manish&hours=45

 

how to add more parameters and change parameters

 

 

 

Posted on Mar 03, 2017 07:12 AM

Hi mvadukul,

Refer the below code.

C#

string testString = "A,B,C,D,E";
// Get reverse string.
char[] charArray = testString.ToCharArray();
Array.Reverse(charArray);
string reverse = new string(charArray);
        
// Get random string.
Random random = new Random();
char[] randomArray = testString.Replace(",", "").ToCharArray().OrderBy(x => random.Next()).ToArray();
string finalString = string.Join(",", randomArray);

VB.Net

Dim testString As String = "A,B,C,D,E"
' Get reverse string.
Dim charArray As Char() = testString.ToCharArray()
Array.Reverse(charArray)
Dim reverse As New String(charArray)

' Get random string.
Dim random As New Random()
Dim randomArray As Char() = testString.Replace(",", "").ToCharArray().OrderBy(Function(x) random.[Next]()).ToArray()
Dim finalString As String = String.Join(",", randomArray)