User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,705 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 3078 | Replies: 3
Reply
Join Date: Dec 2006
Posts: 20
Reputation: michael.ngobeni is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
michael.ngobeni michael.ngobeni is offline Offline
Newbie Poster

Replace String

  #1  
Aug 30th, 2007
I have two questions

1. How do I use a Replace() function in JSP
e.g.
String strName = "My name is";
String strName2 = replace(strName, "is", "is Michael");

2. How do I make a string to start with a capital letter

e.g.
I want david to be David

Thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,134
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 257
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Replace String

  #2  
Aug 30th, 2007
replace() method is for switching characters or character seqeuances. However your example shows switching of strings/regular expresions so there is no point in using it. In this case you should use replaceAll(String regex, String replacement) .You have to be carefull with it, as it will be replace any matching expresion with your replacement string.
String strName = "My name is";
String expression = "is";
String replacement = "is Michael";
String strName2 = strName.replace(expression, replacement);


For second question you have to locate first the word of which you wish to change first character and can do something like this
String str = "david";
String str2 = 	str.replaceFirst( Character.toString(str.charAt(0)), Character.toString(str.charAt(0)).toUpperCase() );
Note please, that String str was in this case declared, where in your case you will have to locate it somehow!
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Dec 2004
Posts: 406
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Pro in Training

Help Re: Replace String

  #3  
Sep 1st, 2007
For the second Q, this http://www.techonthenet.com/oracle/f...ns/initcap.php should do the job
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,134
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 257
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Replace String

  #4  
Sep 1st, 2007
Problem is that michael did not mentioned any DB usage and the recomended answer by you is only for Oracle/PLSQL.Also this function change all words to start with capital letter where from michael post I got impression that he want to do it only on certain words.
However you had a valid sugestion
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 10:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC