Hi
I have a string s="bn1056", i want to jumble characters with in string like s="1n05b6".Which function i have to use.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shaik AliPosted Feb 22, 2010, 12:56 PM
The following code might help you.
In the example i used String.Replace().
string st = "abcdefg";
char[] ch = st.ToCharArray(); // this is used to change & replace character positions
int length = st.Length;
string sResult = string.Empty;
for (int i = 0; i < length-1; i++)
{
sResult= st.Replace(ch[i], ch[length-1 - i]); //replacing i with length-1-i character
//sResult= st.Replace(ch[3], ch[length-1 - i]); //in this i am replacing third character everytime with the char got
// you can play around to get different types by changing index.
Console.WriteLine(sResult); // you will get 6 different type of words
}
Hope this will help.
Please mark as answered if it solved your requirement.
Paruchuri KishorePosted Oct 26, 2009, 4:56 AM
This piece of code might help you.
static private string JumbleWord(string word)
{
char[] ans = new char[word.Length];
string jWord = String.Empty;
for (int count = 0; count <= word.Length - 1; count++)
{
ans[count]=word[count];
}
Random rd = new Random();
for (int count = 0; count <= word.Length - 1; count++)
{
int index = rd.Next(0, word.Length)%word.Length;
char temp = ans[count];
ans[count] = ans[index];
ans[index] = temp;
}
for (int count = 0; count <=word.Length - 1; count++)
{
jWord = jWord + ans[count];
}
return jWord;
}