Hi.. Quick newbie question I have a string: String a = "this is a string"; and i need to get for e.g first 3 characters from it, that output were "thi".. Is any easy way to do it? coz I done this using loop with charAt() function... and also I need to get some characters from middle of string... In VBScript there is functions LEFT() and MID() for performing these operations... How about java? I didn't found it in jsp specification.. Thx in advance..
Ilja What you are looking for is the substring method of the string class. It takes two ints as arguments. The first is the starting index and the second is one greater than the ending index. You can check the API for all the details. Also, this is the JSP forum and your post is not about JSPs. Please try to post questions to the correct forums and you will get better responses.
Hi , Hope this will help. [code] public String substring(int beginIndex, int endIndex)Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. Examples: "hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile" [code]
Joined: Dec 02, 2001
Thx a lot.. I have to read specifications carefully didn't noticed for substring function..