Here you can find the source of left(String str, int count)
Parameter | Description |
---|---|
str | The string to parse. |
count | The amount of characters to return. |
public static String left(String str, int count)
//package com.java2s; /*/*from w w w . jav a2 s . com*/ * Copyright 2010-2017 Boxfuse GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Returns the first n characters from this string, where n = count. If the string is shorter, the entire string * will be returned. If the string is longer, it will be truncated. * * @param str The string to parse. * @param count The amount of characters to return. * @return The first n characters from this string, where n = count. */ public static String left(String str, int count) { if (str == null) { return null; } if (str.length() < count) { return str; } return str.substring(0, count); } }