How do i find the length of a string??

trying to use the substring, I know the beginIndex (in my case 10), but the string will vary in size and so i need to find the last character and set it as the endIndex, how do i do this?
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"
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.

Hi
To substring the string where u know the begin index and want to extract till the end use the following function from the String class of the java.lang package
String substring(int beginindex);
String test = "Hello";
String xx = test.substring(1);
The Value stored in xx will be ello
This is in case u need till the end of the String
If wanna skip the last character u can
use
String substring(int beginindex,int endindex);
String test = "Hello";
String xx = test.substring(1,test.length()-1);
The Value stored in xx will be ell

Similar Messages

  • Find the length of a string in pixels

    Hello all,
    Wondering if there's a way in PowerShell to find the length of a given string in pixels?

    That would depend on the font used to draw it, including size, bold / italic, etc.  Assuming you know those things, there's a TextRenderer.MeasureText method in the Windows Forms library:
    $string = 'This is my string. There are many like it, but this one is mine.'
    $font = New-Object System.Drawing.Font('Arial', 12, [System.Drawing.FontStyle]'Bold, Italic')
    $size = [System.Windows.Forms.TextRenderer]::MeasureText($string, $font)
    $size.Width

  • How can i get the length of a string with Simplified Chinese?

    when i use eventwriter to add content to a xmldocument,there are some chinese simplified string in it,i use String.length() for the length ,but it is not correct~how can i get the right length for eventwriter?

    Below is a simple patch for this problem. Using this patch you need to pass 0 as the length argument for any XmlEventWriter interfaces that take a string length.
    Regards,
    George
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp    Fri Nov  3 12:26:11 2006
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp      Thu Mar 15 13:58:13 2007
    *** 234,239 ****
    --- 234,241 ----
            CHECK_NULL(text);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)text);
            if (!_current)
                    throwBadWrite("writeText: requires writeStartDocument");
            try {
    *** 413,418 ****
    --- 415,422 ----
            CHECK_NULL(dtd);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)dtd);
            if (_current) {
                    if (!_current->isDoc())
                            throwBadWrite("writeDTD: must occur before content");
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp Tue Jan  2 16:01:14 2007
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp   Thu Mar 15 13:59:25 2007
    *** 326,331 ****
    --- 326,333 ----
                    needsEscape = false;
            else
                    needsEscape = true;
    +       if (!length)
    +               length = ::strlen((const char *)chars);
            writeTextWithEscape(type, chars, length, needsEscape);
    *** 336,341 ****
    --- 338,345 ----
                                  bool needsEscape)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)chars);
                    if ((type == XmlEventReader::Characters) ||
                        (type == XmlEventReader::Whitespace)) {
                            char *buf = 0;
    *** 381,386 ****
    --- 385,392 ----
      NsWriter::writeDTD(const unsigned char *data, int len)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)data);
                    _stream->write(data, len);
      }

  • Finding the length of a string

    hi im pretty new to all this,
    I am adding a part to my very basic program where the user can type "y" or "n" after they are being asked if they want to continue, I have been able to do this ok but im trying to make the program as air-tight as possible and i'm having troubble with the error checking.
    I have told the program what to do next based on the first character the user has typed (character 0), I would like my prorgam to prevent continuation if more than one character was entered into the string. At present it still recognises ydr (example) as a valid entry, is there anyway i can detect if there is more than one character in the sting? by doing so i'll be able to throw back an error to the user.
    do
      System.out.println("Would you like to continue (y/n)");
      System.out.println("");
      tmpans = scan.nextLine();
          if (tmpans.length > 1)
          //i know the above method of detecting the length dosn't work with strings, is there an alternative?
            exchar = true;
            System.out.println("You have entered too many characters");
          else
            exchar = false;
          while (exchar);
          if (tmpans.charAt(0) == 'y')
    ... etc

    String.getLength()Errr... String.length() ?Ya right. Whatever. lol
    It's still early in the day for me

  • Find the length of a String, without using any String API

    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please help

    Simratpal wrote:
    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please helpWell I have strongly argued against doing this, (it seems like a pointless exercise), and I have even stated that it cannot be done, even Reflection at some level will use a String method. I have not bothered to dissect wether the same is true with JNI. However, if we take the statement of the original problem exactly as stated, particularly the
    but method should not have any String API.i.e. we don't care if a String API is used 'under the covers', just so long as there is no direct usage in the new method that is written, then the answer is trivially easy:
    public class Main
        public static void main(String args[])
            Main worker = new Main();
            String str = "123456789";
            int len = worker.strLenUsingNoExplicitStringClassMethod(str);
            System.out.println("Length of string \""+str+"\""+" is "+len);
        public int strLenUsingNoExplicitStringClassMethod(String string)
            StringBuilder sb = new StringBuilder(string);
            return sb.length();
    }

  • How to find the length of the resultset

    how to find the length of the resultset

    (Doing a select count as somebody suggested is nota
    good solution, as the count can change betweenyour
    count query and your real query.)And the number of rows can't change between getting
    the last one and doing the actual work?I don't think so. Once you've got the ResultSet, I don't think it will change under you, unless you explicitly set it to SCROLL_SENSITIVE.
    I could be mistaken though.

  • How to Find the length of Infosource?/

    Hi BW Guru's,
    How to Find the length of Infosource?
    Thanks
    Bhima Chandra Sekhar G

    Hi Bhima,
    You can look up the transfer structure (extract structure) in table ROOSOURCE in the active version of the DataSource and determine its size via SE11 (DDIC) -> Utilities -> Runtime object -> Table length.
    Hope it helps!
    Bye,
    ROberto

  • How is the length of a string calculated in Java?  and JavaScript?

    Hi all,
    Do any of you know how the length of a string is being calculated in Java and JavaScript? For example, a regular char is just counted as 1 char, but sometimes other chars such as CR, LF, and CR LF are counted as two. I know there are differences in the way Java and JavaScript calculate the length of a string, but I can't find any sort of "rules" on those anywhere online.
    Thanks,
    Yim

    What's Unicode 4 got to do with it? 1 characteris 1
    character is 1 character.
    strings now contain (and Java chars also) is
    UTF-16 code units rather than Unicode characters
    or
    code points. Unicode characters outside the BMPare
    encoded in Java as two or more code units. So it would seem that in some cases, a single
    "character" on the screen, will require two charsto
    represent it.So... you're saying that String.length() doesn't
    account for that? That sux. I don't know. I'm just making infrerences (==WAGs) based on what DrClap said.
    I assume it would return the number of chars in the array, rather than the number of symbols (glyphs?) this translates into. But I might have it bass ackwards.

  • Chnage colum from CLOB to Varchar2 and find the length of CLOB

    Hi,
    I have got tables contain CLOB fields. I want to converter them to varchar2? Is the a way to do it? how can I find the max of length the data in CLOB fields.
    Thanks in advance!!
    Michael

    Hi All,
    Thanks you for your useful information. What I need is to change the colum data type (definaition itself)from CLOB to Varchar2, not just to display the values in CLOB field into varchar2. I have tried to change the date type from COLB to varchar2 in TOAD and got ORA_22859: invaliad modification of columns.
    Any suggestions?
    Many Thanks
    Michael

  • How do I extend the length of time my iphone rings before voicemail cuts in? If I need to use a password, how do I access that on my iphone? I'm a new user.

    HELP!! My voicemail cuts in after just 15 seconds of ringing, which is rarely long enough for me to answer it. How do I increase the length of time it rings? Can I choose not to have voicemail at all, so my phone can just continue ringing until I answer?
    If I need to enter a voicemail password or key, can you tell me step by step because I can't see how to do anything except retrieve and delete voicemail msgs. I'm on O2-UK, if that makes any difference at all. Thank you

    If my response has been either helpful or correct, could you indicate that marking which it is in order that others searching for a similar solution can find find this easily.
    FYI, it's considered bad forum etiquette to ask for points.

  • How can I find the index from a specific container?

    How can I find the index from a specific container?
    For example, if I'm traversing through textframes like so (an example, not tested):
    var doc = app.activeDocument;
    var story = doc.pages[0].textFrames[0].parentStory;
    for (var i=0, l=story.textContainers.length; i<l; i++) {
         var textFrame = story.textContainers[i];
         if (textFrame.constructor.name == "TextFrame") {
              var lastPara = textFrame.paragraphs.lastItem();        //How can I find the index of this in relation to the story?
    How can I find the index of "lastPara" in relation to the story rather than the current container?
    I tried:
    var newPara = story.paragraphs[lastPara.index];
    but this results in an invalid object. . .
    alert(newPara.isValid);      //returns false

    The .index property is the character offset. So lastPara will begin at story.characters[lastPara.index].

  • Finding the length of a path

    hey,
    i'm using cs3 and i have a few simple paths (curves) and i'd like to know the length of these curves but i can't seem to find an option, or whatever, for that.
    thanks

    You mean the length as you travel along the curves?
    Can't be done I'm afraid, at least not very accurately.
    If it's really important you could try arranging a whole lot of little squares along the path so that they touch each other and then counting them. But the result won't be accurate unless the squares are very small.
    However, if you know how the curves are constructed geometrically you can sometimes calculate their lengths.
    For example if the curve is an arc of a circle and you know the angle it subtends as a proportion of 360 degrees then it's fairly easy to use pi to find the length of it.
    Circumference of a circle = pi x diameter.
    "As every skoolboy kno" (nigel molesworth)
    Ellipses are more of a bother and I don't know the formulas for sinus curves, parabolas and that sort of thing.

  • How can if find the most repeated character and number ???

    Hi,
    I have a question. For instance, if we have a text file which contains:
    aaabbbhhhhhhtttttsjs12366
    How can i find the most repeated character and number. I have to add this code to the following program:
    I will aprreciate if you can help.
    Regards,
    Serkan
    import java.io.*;
    public class LineLen {
         public static void main(String args[]) throws Throwable {
              final String filename = "deneme1.txt";
              BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
              String line = infile.readLine();
              int linenum = 0;
              while (line != null) {
                   int len = line.length();
                   linenum++;
                   System.out.print(linenum + "\t");
                   for (int i = 0; i<len; i++)
                   System.out.print("*");
                   System.out.println("");
                   line = infile.readLine();
    }

    For a small alphabet like English, array migt be used:
    //in a for loop
    ++array[s.charAt(i)];For a big alphabet like chinese, HashMap might be barely used:
    map.put(s.charAt(i), increment(map.get(s.charAt(i))));
    // increment is a user defined method, possibly for an Integer object,
    // that returns a new Integer object

  • How we can find the last character in a string(Urgent Plz!)

    Gurus!
    How we can find the last character in a string.
    e.g i have a string say "Str" with value "10-01".
    Now i want to find the last character in "Str" i.e "ONE=1".
    i am using Oracle developer 6i with Oracle 8i(1.7).
    Plz help!
    Many thanks!

    Use the substr() and length() functions -
    x := '10-01';
    y := substr(x, length(x));

  • I have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    i have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    Maybe it is in the Purchased category of iTunes,
    Try going there

Maybe you are looking for

  • Order of  events in abap

    Hi,      this is kiran,can any one send the order for events in abap. regards, kiran

  • My iPhone won't display its apps in iTunes

    My wife's iPhone is connected to her PC, but the Home Screens for the apps won't display in iTunes.

  • Types of users

    hi guys, can you explain me the types of users (power, core, end or biz users) in terms of which i can relate say eg ceo etc and their roles in terms of usage of BW reports, can you also mention the volume of users in  a typical data-consuming MNC. t

  • Simple Java Complier - !

    Dear Experts There are a bunch of 8th Grade Kids who want learn to code simple console applications in JAVA under windows. Until now i had the JDK1.2.2 System but i have lost the file. Can you please give me pointers from where i can get the latest c

  • Change Material non-valuated to material valuated

    Hi experts, I have created a material before doing settings in transaction OMS2, so this material was created as non-valuated. After that, I have changed the settings in transaction OMS2 (I have marked qty updating and value updating). I'd like to ch