Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hy, I have this code :
<pre lang="vb">
Dim RandomNumber As New Random()
Dim msg As String = "My name is Nick from Neptune"
</pre>
and I want to replace each space from msg with random numbers so it will sound like this
My12name455is22Nick88from66Neptune

Can anyone help me with this?

Thanks in advance and sorry for my English
Posted

What you are trying to achieve is easy to implement.
Run a while loop on the string until spaces are found (using IndexOf).
Till you keep getting a blank, replace with a random number.

Have a look at the String.Replace method[^].

Pseudo code would look like -
while (s.IndexOf(' ') != -1)<br />
{<br />
   s.Replace(' ' ,RandomNumber.ToString();<br />
}
 
Share this answer
 
Hy Abhinav S
I am using MVS2010 and the program is build in windows Forms
Thanks for your help but is does not work.
I will be very happy if you could convert the above script for Windows Forms.
Thanks in advance
 
Share this answer
 

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