| | |
Replace character at a particular position
Please support our JavaScript / DHTML / AJAX advertiser: $6.99 Domain Names at 1&1. Includes Free Privacy. Save Now!
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 327
Reputation:
Solved Threads: 7
function ConvertToUpperCase()
{
var result;
var numaric = "sonia";
var Character = numaric.charAt(0);
result=Character.toUpperCase();
//In Result char is coming in UpperCase
//I want how to replace the charater at postion 0 in numaric with result
} Hi sonia,
you could try this:
you could try this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function ConvertToUpperCase() { var result; var numaric = "sonia"; var Character = numaric.charAt(0); result = numaric.replace( Character, Character.toUpperCase() ); // Converting target character to uppercase letter. }
Last edited by essential; Aug 2nd, 2009 at 1:18 pm.
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 1
I would try something like:
This changes the first character to upper case and then adds the second and subsequent character to the end.
HTH
Stoo
--
<FAKE SIGNATURE>
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function ConvertToUpperCase() { var result; var numaric = "sonia"; result=numaric.charAt(0).toUpperCase() + numaric.substring(1); }
This changes the first character to upper case and then adds the second and subsequent character to the end.
HTH
Stoo
--
<FAKE SIGNATURE>
Last edited by peter_budo; Aug 4th, 2009 at 4:57 am. Reason: Keep It On The Site - Do not manually post "fake" signatures in your posts. Instead, you may create a sitewide signature within the user control panel.
That will only work if you the 1st spot of character. What if she tries to point it out at
-essential
Character = numaric.charAt( 2 ); ? Of course it will be needing some workaround that includes looping process, which will keep the line a bit longer compare to the used of the replacement method. If you are building programs, try to think what is on up ahead, not just things that you can do right now...-essential
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
•
•
Join Date: Mar 2008
Posts: 327
Reputation:
Solved Threads: 7
THX BOTH OF U
Working Code
Suppose i type miss sonia sardana in textbox when the control loss focus or when we press tab.output is Miss Sonia Sardana..Although its long process,because there is no way to replace character at a particular position in string...any better ideas are welcome?
Working Code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { txtCompanyName.Attributes.Add("onblur", "javascript : ConvertToUpperCase()"); } } catch (Exception ex) { lblStatus .Text =ex.Message .ToString (); } } function ConvertToUpperCase() { var numaric = document.getElementById ("txtCompanyName").value; numaric =numaric.charAt(0).toUpperCase() + numaric.substring(1); var pos = numaric.indexOf(" "); while(pos > -1) { numaric =numaric.substring(0,pos+1) + numaric.charAt(pos+1).toUpperCase() + numaric.substring(pos+2); pos = numaric.indexOf(" ", pos+1); } document.getElementById ("txtCompanyName").value=numaric; }
Suppose i type miss sonia sardana in textbox when the control loss focus or when we press tab.output is Miss Sonia Sardana..Although its long process,because there is no way to replace character at a particular position in string...any better ideas are welcome?
Last edited by sonia sardana; Aug 2nd, 2009 at 3:11 pm.
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 1
•
•
•
•
That will only work if you the 1st spot of character. What if she tries to point it out atCharacter = numaric.charAt( 2 );? Of course it will be needing some workaround that includes looping process, which will keep the line a bit longer compare to the used of the replacement method. If you are building programs, try to think what is on up ahead, not just things that you can do right now...
-essential
--
<FAKE SIGNATURE>
Last edited by peter_budo; Aug 4th, 2009 at 4:57 am. Reason: Keep It On The Site - Do not manually post "fake" signatures in your posts. Instead, you may create a sitewide signature within the user control panel.
Sonia,
You might like to try something like this:
Airshow
You might like to try something like this:
javascript Syntax (Toggle Plain Text)
//This is a general utility function that returns an Initial Caps version of the input string function initialCaps(str){ var a = str.split(' '); for(var i=0; i<a.length; i++){ ch = a[i].charAt(0); a[i] = a[i].replace(ch, ch.toUpperCase()); } return a.join(' '); } //This function is applies initialCaps() to a specified form field. function field2InitialCaps(filedId){ var f = document.getElementById (filedId); if(f) { f.value = initialCaps(f.value); } }
html Syntax (Toggle Plain Text)
<!-- Demo --> <input id="txtCompanyName" type="text" value="sonia is a beautiful name" size="50" /><br /> <a href="" onclick="field2InitialCaps('txtCompanyName');return false">Convert to Initial Caps</a>
50% of the solution lies in accurately describing the problem!
![]() |
Similar Threads
- catch a character at a position (C++)
- void pointers (C++)
- Help Please - with String Manipulation (C++)
- Howto | mssql seach and replace? (MS SQL)
- Serialization to XML + Encryption (C#)
- help me in statement (C++)
- Update to completly lost : ) (Java)
- Cryptography Fun (Python)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: inserting img into table
- Next Thread: generating a table structure using JQuery
Views: 1434 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
8 ad ajax ajaxcode ajaxhelp animate api array asp asp.net autoplay box boxes bug catch close code content cookies css date dependent design div dom download draganddrop dropdown dynamic element embed error eventhandlers events explorer ext file firefox firehose flash focus font form forms function gears google gxt hide html ie7 iframe image image() internet internet-explorer java javascript javascripts jawascriptruntimeerror jquery js libcurl lists load maps media modal mysql onclick onmouseover parameters paypal php player position post resize reveal script scroll scrubber search select show simple size smarty source sources text textbox twitter unicode validation variables web webkit window xml





