Solved

left Function in java

Posted on 2003-12-04
5
7,771 Views
Last Modified: 2010-05-18
In VB this is a function, Left(string, length)  : Returns a Variant (String) containing a specified number of characters from the left side of a string.

is there anything like this in java? thanks
0
Comment
Question by:ocsurf
  • 4
5 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
ID: 9878455
substring(0, length)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9878469
System.out.println("Hello".substring(0, 3));

would output

Hel
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9878485
Cool thanks...Can this be applied to int numbers too?
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9878501
You'd need to convert the int to a String first:

int myInt = 12345;
Integer.toString(myInt).substring(0, 3);

would give you:

123
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9878531
;-)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question