[program-java] Re: Strings

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <program-java@xxxxxxxxxxxxx>
  • Date: Tue, 21 Apr 2009 17:03:15 -0400

How about this?

s = s.substring(0, 1).toUpperCase() + s.substring(1);

If you want to capitolize the first letter and lower case the rest of the
string, then simply do this:

s = s.substring(0, 1).toUpperCase() + s.substring(1);

Don't waste time checking whether the first letter isn't capitolized. You
will spend more time checking, than if you just did this operation on all
strings.

Again, let me reitterate this does not create compliant class names.

Take care,
Sina

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Tuesday, April 21, 2009 4:40 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Strings

Hi:

I essentially peeled off the first char, forced it to upper case. Next I
grabbed the rest of the string minus the first char and then put it back
together but that's greasey.

I was hoping for something like this:

If first char is not capital then 
Make first char capital
End if

Many thanks

Jim 

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: April 21, 2009 16:32
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Strings

Two answers.

Sure, you can do a toUpperCase on the first char of the string, but this
does not make it any more legitamet.  Basically, if you have something like
EmployeeRecord, go back and jaws cursor over how I spelled that.  Noticed
that each word needs to be capitolized.  Therefore, capitolizing the first
letter only is honestly no more correct than just leaving them all lower
case.  If it's automated, then you don't have to have them be upper case,
that's simply a strongly enforced and suggested style guideline.

Regardless, here are the two javadoc pages you need for the string and char
classes:

String

http://java.sun.com/javase/6/docs/api/

Character

http://java.sun.com/javase/6/docs/api/

Take care,
Sina

________________________________

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Tuesday, April 21, 2009 4:03 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Strings



Hi: 

I'm writing a program that will take a COBOL copybook record layout and
creates automatically a java class with the corresponding fields, getters
and setters and the necessary code for my CICS to CICS transaction.

The UI is complete and so is most of the backend logic and now I'm just
cleaning things up.... 

One thing I want to do is once I've selected my .cbl file from a file dialog
is to check the first character of the file name.... If its lower case then
convert it to upper case because the existing file name eventually becomes a
.java file and as a standard all .java classes start with a capital
letter....

I guess I'm looking at this way to hard because for the life of me I can't
seem to dig my self out of this hole. Any ideas?

Jim 

James M. Corbett 

A / Technical Specialist
GST/HST Micros | Micros de la TPS/TVH
GST/HST Redesign Division | Division de la restructuration de la TPS/TVH
Revenue and Accounting Systems Directorate (RASD) | Direction des Systèmes
de revenu et de comptabilité (DSRC) Information Technology Branch (ITB) |
Direction générale de l'informatique
(DGI)
Canada Revenue Agency | Agence du revenue du Canada 

(613) 941-1338 

"...Is a hippopotamus a hippopotamus, or just a really cool Opotamus?" 





Other related posts: