Solved

left Function in java

Posted on 2003-12-04
5
7,773 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 72
Java string replace 11 61
Convert from a json string array to a Java object 3 63
learn programming 8 66
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

685 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