473,411 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

replace help

CK
Hi Guys,
I need a function that will replace the letter after a "hyphen" with a
capital letter.
Like if the user enter "Zeta-jones" it would be "Zeta-Jones".
I am a little stumped. Any ideas? I know it's a combination of substring
and replace and toUpper().
I just can't get the method call correctly.

I use iHyphen = x.indexOf("-");

I need to replace the letter after the hyphen with the uppercase version of
the letter.

Any ideas?
Thanks,
Chris
Jan 10 '06 #1
3 2115
CK wrote:
Hi Guys,
I need a function that will replace the letter after a "hyphen" with a
capital letter.
Like if the user enter "Zeta-jones" it would be "Zeta-Jones".
I am a little stumped. Any ideas? I know it's a combination of substring
and replace and toUpper().
I just can't get the method call correctly.

I use iHyphen = x.indexOf("-");

I need to replace the letter after the hyphen with the uppercase version of
the letter.
You can use the following function based on a post from Baconbutty[1]:

var s="Zetta-jones-smith-walker";
var r=/(-)([a-z])/g;
s = s.replace(r,function(a,b,c){return '-' + c.toUpperCase();});
alert(s);

But note that it will not work in old browsers (or some newer ones), but
that is fixable (follow the thread down).

1.
<URL:
http://groups.google.co.uk/group/com...776c776ce21e48

--
Rob
Jan 11 '06 #2
CK
Unfortunately that strips out the hyphens. Thanks. Here's what I came up
with.

iHyphen = x.indexOf("-");
if(iHyphen > - 1)
{
output = x.replace(x.substr(iHyphen+1,
1),x.substr(iHyphen+1,1).toUpperCase());

}


"RobG" <rg***@iinet.net.au> wrote in message
news:um****************@news.optus.net.au...
CK wrote:
Hi Guys,
I need a function that will replace the letter after a "hyphen" with a
capital letter.
Like if the user enter "Zeta-jones" it would be "Zeta-Jones".
I am a little stumped. Any ideas? I know it's a combination of
substring and replace and toUpper().
I just can't get the method call correctly.

I use iHyphen = x.indexOf("-");

I need to replace the letter after the hyphen with the uppercase version
of the letter.


You can use the following function based on a post from Baconbutty[1]:

var s="Zetta-jones-smith-walker";
var r=/(-)([a-z])/g;
s = s.replace(r,function(a,b,c){return '-' + c.toUpperCase();});
alert(s);

But note that it will not work in old browsers (or some newer ones), but
that is fixable (follow the thread down).

1.
<URL:
http://groups.google.co.uk/group/com...776c776ce21e48

--
Rob

Jan 11 '06 #3
CK wrote:

Please dont' top-post.

Unfortunately that strips out the hyphens.
The original does, the version I posted doesn't (see below).

Thanks. Here's what I came up
with.

iHyphen = x.indexOf("-");
if(iHyphen > - 1)
{
output = x.replace(x.substr(iHyphen+1,
1),x.substr(iHyphen+1,1).toUpperCase());

}
If your hyphenated words may ever have more than one hyphen, or if the
first letter may not be already capitalised, then:

function hyCase(str)
{
var s=[], ss=str.split('-'), i=ss.length;
while ( i-- ){
s[i] = ss[i].substr(0,1).toUpperCase() + ss[i].substr(1);
}
return s.join('-');
}

alert(hyCase('zetta-jones-smith-walker'));
may suit better.


"RobG" <rg***@iinet.net.au> wrote in message
news:um****************@news.optus.net.au...


[...]

You can use the following function based on a post from Baconbutty[1]:

var s="Zetta-jones-smith-walker";
var r=/(-)([a-z])/g;
s = s.replace(r,function(a,b,c){return '-' + c.toUpperCase();});
alert(s);

But note that it will not work in old browsers (or some newer ones), but
that is fixable (follow the thread down).

1.
<URL:
http://groups.google.co.uk/group/com...776c776ce21e48

--
Rob
Jan 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
6
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? ...
2
by: Barnes | last post by:
Hi, Can anyone please tell me how I can use the replace method to replace a character if it occures in more than one textbox without having to write separate function for each textbox. The...
5
by: Mahesha | last post by:
Hello, I need help in replacing one string pattern with another. Ex: I have a financial security expression like log(T 3.25 6/24/2004)/sqrt(T 4.5 6/19/2002) Here "T 3.25 6/24/2004" is a...
2
by: cloudx | last post by:
Hi there, Here is the line of VB code and I would like to translate into C#, please help! Thanks! sMsgIntHeader = (Replace(Replace(Trim(Left(sErrorMsg, InStr(5, sErrorMsg, vbCrLf))), vbLf,...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
16
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario =...
1
by: Random Task | last post by:
Can someone help me by providing an example of how to replace / with \ in a string in xslt2. The characters / and \ seem to cause me grief ... I am trying the below code currently ... Any...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
8
by: Warren Moxley | last post by:
Hi there, i've been searching for a C String search and replace function. I need to find all occurrences of " " in a char* array, and replace them with another char, I know how to do this in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.