• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TitleCasing a String - probably a java question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: TitleCasing a String - probably a java question
      • From: Geoff Hopson <email@hidden>
References: 
 >Re: TitleCasing a String - probably a java question (From: "Jonathan Fleming" <email@hidden>)

  • Prev by Date: Re: Getting A Value From An NSArray
  • Next by Date: Re: TitleCasing a String - probably a java question
  • Previous by thread: Re: TitleCasing a String - probably a java question
  • Next by thread: Re: TitleCasing a String - probably a java question
  • Index(es):
    • Date
    • Thread