Re: TitleCasing a String - probably a java question
Re: TitleCasing a String - probably a java question
- Subject: Re: TitleCasing a String - probably a java question
- From: Geoff Hopson <email@hidden>
- Date: Tue, 6 Jan 2004 09:26:40 +0000
Like I said, never used it...probably need to do something tricky like
initialize D2W or something.
Here's a method instead - put this somewhere "useful":
public static String capitalise(String oldStr) {
int len = oldStr.length();
if (oldStr == null || len == 0) {
return oldStr;
}
StringBuffer buff = new StringBuffer(strLen);
boolean white = true;
for (int i = 0; i < len; i++) {
char c = oldStr.charAt(i);
if (Character.isWhitespace(c)) {
buff.append(c);
white = true;
} else if (white) {
buff.append(Character.toTitleCase(c));
white = false;
} else {
buff.append(c);
}
}
return buff.toString();
}
Never used it, but this is lurking in the WebObjects libraries...
http://developer.apple.com/documentation/WebObjects/Reference/API/
com/ webobjects/directtoweb/Services.html
Guess you just do:
String capitalizedString = Services.capitalize(oldString);
Let me know how it goes...
Yes, Geoff,
I went down this route and got this error after importing the class:
cannot resolve symbol
symbol : class Services
location: package directtoweb
import com.webobjects.directtoweb.Services; (Service is indicated with
a ^)
import com.webobjects.directtoweb.Services;
public String capitalizedString() {
String myString = companyName() !=null ? companyName() : fullName();
return myString;
}
Any ideas how to resolve it?
Jonathan :^)
GEoff
On 6 Jan 2004, at 07:48, Jonathan Fleming wrote:
What's the best way to go about making a String TitleCase eg.
turning: "commited to the future of webObjects" into "Commited To
The Future Of WebObjects".
I can't seen to find a Webobjects utility or method that does this.
TIA
Jonathan :^)
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
--
Geoff Hopson
Objectology Ltd.
http://www.objectology.co.uk/
_________________________________________________________________
Express yourself with cool new emoticons
http://www.msn.co.uk/specials/myemo
--
Geoff Hopson
Objectology Ltd.
http://www.objectology.co.uk/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.