• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string convert?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

can you tell me how do i place the first letter of the english word at the end of the word and add the letters "ay". like "jump", it will become "umpjay".
thanks in advance.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the String class, in particular the String.charAt(), String.substring(), String.concat() (the + operator) methods.
If you are concerned about efficiency you can consider also using the StringBuffer class.
 
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry;


Take a look at the String class, in particular the String.charAt(), String.substring(), String.concat() (the + operator) methods.


If String intput = "1234" then
input.charAt( 1 ) == "2" ;
int num = input.charAt( 1 ) ; returns 50
int num = Integer.parseInt( input.charAt( 1 ) );
returns

String num input.charAt( 1 ) ; returns "inconvertalbe types"
I want the integer 2.
Cant't turn this calf out 'til it is branded and ear marked!
TIA
doco
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Create a few methods like this to create the pig latin word.
hope this helps
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Yuan has now been practically shown in detail how to do it :-


And for doco :- Integer.parseInt() takes a String as an argument not a char. One way to convert a char to a String is to "add" it to "" (the empty string).
For example:
String two = "" + "1234".charAt( 1 );
[ March 12, 2003: Message edited by: Barry Gaunt ]
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my bad
 
Donald R. Cossitt
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry;

That's pretty cool! Now where can me and ol' Dobbin go to get a better understanding of how that works? :roll: Be gentle
Thanks
doco
 
Donald R. Cossitt
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind, I figured it out. It's the same principle as System.out.println( "this " + 1 + 1 );
versus
System.out.println( 1 + 1 + " that" );
doco
[ March 12, 2003: Message edited by: doco mastadon ]
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic