Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I would like to be able to type a word or name into an box, click a generate button and have some of the letters or words changed into a new box.

For example:
John Smith > Juhn Smith
(change the 'o' to 'u' making Juhn Smith)
or
John Smith > Ron Smith
(change whole words)

What I have tried:

I have tried looking at strings and replacewith() but have not found anything suitable online especially nothing using input boxes.

Thanks
Posted
Updated 26-Apr-17 7:24am

1 solution

The simplest way to do this would be to convert the string to a character array, "mutate" the array, and change it back.
That's pretty simple:
string output = new string(Mutate(input.ToCharArray()));
...
private char[] Mutate(char[] data)
   {
   ...
   }
The Mutate method isn't difficult either: use the Random class to generate a value between 0 and 25, and use that as an index into an array of letters:
private string letters = "abcdefghijklmnopqrstuvwxyz";
(Because a string is a collection, you can use an index on it to retrieve an individual character)
Decide which letters to change, and do it!
 
Share this answer
 
Comments
Member 13154265 26-Apr-17 14:01pm    
Thank you but what do you mean 'and change it back?' how do you mean? do you use jsbribble - i might be able to get my head round that! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900