Posted: 5/23/2010
Hi experts,
I have a string in jabvascript . There is a requirement to replace all the blank spaces with a particular character . How can I do so ?
Posted: 5/26/2010
This will serve you : val.replace(/\s/g, "x") where x is your character. Below is the sample:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Test" OnClientClick="return test()" /> <br /> </form> <script type="text/javascript"> function test() { var txtBox1 = document.getElementById('<%= TextBox1.ClientID %>'); var val = txtBox1.value; var replacedValue = val.replace(/\s/g, "X"); alert(replacedValue); return false; } </script> </body> </html>