7 Replies - 6689 Views - Last Post: 05 May 2005 - 11:49 AM Rate Topic: -----

#1 gaming_god  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-May 05

help with java

Post icon  Posted 05 May 2005 - 11:23 AM

How exactly do you use charAt in java. I understand some of the basics but how do I allow for it to read each character.
Is This A Good Question/Topic? 0
  • +

Replies To: help with java

#2 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 782
  • View blog
  • Posts: 7,610
  • Joined: 05-May 05

Re: help with java

Post icon  Posted 05 May 2005 - 11:28 AM

Your 'String' is an array of characters.
It's (kind of) like char word[]; in a sense.
for example:

String name = new String("Bob");

understand? Then:

name.charAt(0) = 'B';

is true and:

name.charAt(2) = 'b';

and finally:

name.charAt(1) = 'o';

so to read characters, say it as an array. Use a for or while loop.
To look one step ahead of the array, say it like this when num is zero:

name.charAt(num+1) = 'o';

Does that help you?
Was This Post Helpful? 0
  • +
  • -

#3 gaming_god  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-May 05

Re: help with java

Posted 05 May 2005 - 11:29 AM

thanks
Was This Post Helpful? 0
  • +
  • -

#4 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 782
  • View blog
  • Posts: 7,610
  • Joined: 05-May 05

Re: help with java

Posted 05 May 2005 - 11:30 AM

I know that helped you.
I am more helpful over the computer than in person.
Was This Post Helpful? 0
  • +
  • -

#5 BlackJesus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 161
  • Joined: 10-February 05

Re: help with java

Posted 05 May 2005 - 11:42 AM

so will this work?

char test = new char[50];
String input;
input = Keyboard.readString();
for(int i = 0; i < input.length(); i++)
{
blah[i] = input.charAt(i);
}
Was This Post Helpful? 0
  • +
  • -

#6 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 782
  • View blog
  • Posts: 7,610
  • Joined: 05-May 05

Re: help with java

Post icon  Posted 05 May 2005 - 11:44 AM

Sounds like a good idea.
Try it out, I see no reason why it shouldn't work.
Was This Post Helpful? 0
  • +
  • -

#7 BlackJesus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 161
  • Joined: 10-February 05

Re: help with java

Posted 05 May 2005 - 11:48 AM

ok cool that worked out....thanks for the help =)
Was This Post Helpful? 0
  • +
  • -

#8 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 782
  • View blog
  • Posts: 7,610
  • Joined: 05-May 05

Re: help with java

Post icon  Posted 05 May 2005 - 11:49 AM

You are welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1