Calculate length of a string

Hello.
I have written a function to calculate the length of a string, it gives the wrong length can you help me fix the codes?
public int GetStringLength(String z)
int y = 1;
int x = 0;
while (1 > 0)
try
char m = z.charAt(y);
x = x + 1;
y = y + 1;
catch (Exception fini)
return x;
}

Hello.
I have written a function to calculate the length of
a string, it gives the wrong length can you help me
fix the codes?
public int GetStringLength(String z)
int y = 1;
int x = 0;
while (1 > 0)
try
char m = z.charAt(y);
x = x + 1;
y = y + 1;
catch (Exception fini)
return x;
}Now that's what I call scratching ones belly by wrapping one's arm around one's backside until reaching the belly.

Similar Messages

  • How to calculate length of the string in transformation file

    Hello all
    I have tried a number of ways and I am not able to calculate the length of the incoming field in transformation file for my data load. Here is the issue.
    I have an incoming string of length 10 and I need to use it to update multiple dimensions which will need first 2, 4 ,6 , 8 characters respectively.
    Now in transformation file ID=ID(1:2) works perfect. However, the BW InfoObject will have multiple values as shown below:
    ID
    Description
    AB
    Business
    ABCD
    Business Organization
    ABCDEF
    Business Line
    ABCDEFGH
    Product Family
    ABCDEFGHIJ
    Product Line
    ABCDEFGHIJKL
    Brand
    I want to update my dimension for Business Organization. I need to update only the records where the length of the incoming string is 4. If I do ID(1:4), I will get the duplicate records and will see the ID less than 4 characters in rejected records. The latter is not such a big issue but the former one is as I need to fetch the right description as well. The formula should check the length and then only pass the record else a dummy value.
    A formula to achieve this in the transformation file is what I am looking for.
    Regards
    Gajendra

    Thanks Vadim for the quick response!
    I am also trying something similar and really appreciate your input here. However, I am not sure if the conversion is really happening.
    Here is what I have done:
    But the strings <> 4 in length are still passing through.

  • How to calculate the length of a string

    Hi everyone,
    A simple question. How to calculate the length of a string?
    Thanks!

    Hi Wuyia Nata,
      As everyone has suggested you search the forum before posting a question, i guess for basic questions u never have to post a question, you will get the answer in your search. Anyways see the code below for string lenght.
    Data:
      w_string type string,
      w_lenght type i.
    w_string = 'vhdskbvsdkbvdsvnsknvs'.
    w_lenght = strlen( w_string ).
    Write:
      w_lenght.
    With luck,
    Pritam.

  • 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.

  • Length of a string in a combobox exceeds the width of the combobox

    How do you fix this:
    The length of a string in a combobox exceeds the width of the combobox and as a result, the comboBox changes its size :-(
    I don't want it to change the size even if the length of the string exceeds the width of the comboBox
    what should i do?

    ok i got it
              Dimension d =combo.getPreferredSize();
    combo.setPreferredSize(new Dimension(50, d.height));
    anyone with better solution?

  • How to find the total length of the string drawed in a rect?

    Hello Everybody,
    I am drawing a string in on one rect using drawInRect method. This drawInRect method gives us a return value as size of the rect. I need length of the string that is did draw in that rect, but didn't find any api to do this.
    Can anyone tell me , how find the length of the string which we did draw in rect?
    Any help regarding this issue , is highly appreciable.
    Thanks,
    Pandit

    Hi Adreas,
    First of all, very thanks for the response.
    Actually , I am looking for other thing. Using drawInRect method I am drawing contentString in self.rect like below.
    //code
    [contentString drawInRect:self.rect withFont:[UIFont fontWithName:@"Verdana" size:14.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
    //End
    My contentString is much larger string, so I am not able to draw it in rect(length: 320.0 height: 460.0) completely. My rect is showing only a part of a contentString. So I need to get that part of string which did draw in the rect, so that I can process my contentString to get the remaining string to draw it a next rect.
    The above code statement is returning me the CGSIZE , it is giving the size of the rect but not giving any information of the string which get draw in that rect.Do you have any idea how to do this?
    Any information on this is highly appreciable.
    Thanks,
    Pandit

  • Length of a string without using any built-in functions

    code that returns the length of a string without using any built-in functions.
    thanks
    Sam

    A string is internally represented by a character array.  An array of characters will reside on the stack, not the heap.  Yes, we always learned that String is a reference type, but what goes on in your memory might still surprise you...
    A struct is internally represented by only it's private properties, sequentially on the stack.
    So basically, what I thought is happening by messing with the structlayout: is only tricking our programming a bit into thinking that the top X bytes on the stack represent a chararray, while actually we put them there as a string.
    Wrong. True. And wrong.
    A string is internally represented by, in that order, an array length, a string length, the chars. None of them resides on the stack.
    An array is internally represented by, in that order, an array length and the chars. None of them resides on the stack.
    When you use the FieldOffset attribute to handle the string as a char array, you don't get anything right:
    - the Length returned is the "array length" of the string, which is equal to the string length + 1.
    - the chars returned by the array indexer are shifted by 2 chars (the length of the "string length" field).
    You can use the FieldOffset to make that work, but it needs a little bit more work.
    unsafe static int Test()
    string myString = "This string may contain many string inside this string";
    string testString = "string";
    int countResult = 0;
    fixed (char* myChars = new StringToChar { str = myString }.chr, testChar = new StringToChar { str = testString }.chr)
    // The 2 first chars of the array are actually the string length.
    int myCharsLength = myChars[1] << 16 | myChars[0];
    int testCharLength = testChar[1] << 16 | testChar[0];
    for (int i = 0; i < myCharsLength - testCharLength + 1; i++)
    if (myChars[i + 2] == testChar[2])
    for (int j = 1; j < testCharLength; j++)
    var c = testChar[7];
    if (myChars[i + 2 + j] != testChar[j + 2])
    goto endOfCharAnalyses;
    countResult++;
    endOfCharAnalyses:
    continue;
    return countResult;

  • Length of the string passed to rwcgi60 in Oracle 6i

    Hello,
    I am running the report from the web. The url will be something like
    http://localhost/cgi-bin/rwcgi60.exe?server=repserver+report=.rep+all the input parameters.
    When the length of the string passed from report= execeeds certain limit(indicated by dashes) I am getting the cgi error
    Error: The requested URL was not found, or cannot be served at this time.
    Oracle Reports Server CGI - Unable to communicate with the Reports Server.
    If I remove some of the select criteria then I could execute the report from the web.
    Any body has any soln. for this.
    Thanks in advance,
    Vanishri.

    Vanishri
    The limit is very high and you should not be hitting this problem. There are couple of fixes done in this area. Please apply the latest patch (Patch 10) and try.
    Other solution is you can have a mapped key in cgicmd.dat file and use the key alone in the URL. In the cgicmd.dat file, you have to map say
    key1: REPORT=your_report.rdf USERID=user_name/password@mydb DESFORMAT=html
    SERVER=repserver DESTYPE=cache
    Please refer to the Publishing reports or Reports services manual at http://otn.oracle.com/docs/products/reports/content.html
    Thanks
    The Reports Team

  • PowerShell: Want to get the length of the string in output

    Hi All,
    I am typing this but it is not working. Does anyone know what I could be doing wrong.
    The command I wrote is:
                         GCI -file  | foreach {$_.name} | sort-object length | format-table name, length
    But it is not working. I am expecting a name of the file and length of the string like 8 characters etc. my file is called mystery so it should have 7 as its output of the name, length.
    Thank-you
    SQL 75

    Get-ChildItem supports both  -File and -Directory.
    Help will help:
    https://technet.microsoft.com/library/hh847897(v=wps.630).aspx
    Read the first couple of parameters to see.
       GCI -file  | sort-object length | format-table name, length | ft -auto
    Seems to be a rasher of bad answers to day.  YOu were just extracting the name property then trying to sort on a property that doesn't exist.
    Do the sort first then select the properties.
    it helps to test answers before posting.  I know because I get bit by posting without thinking to often.  I have to remember to think first.
    ¯\_(ツ)_/¯

  • How to calculate Length of service for an employee

    Hi All,
    I need to calculate Length of Service for an Employee in PA.
    Is there any Function Module for that?
    Thanks and Regards
    Partha.

    Here is what we use in our reports...
        CALL FUNCTION 'COMPUTE_SEARVIS_YEARS_J'
          EXPORTING
            first_date                  = start_date
            second_date                 = end_date
          IMPORTING
            years_between_dates         = llength_service
          EXCEPTIONS
            sequence_of_dates_not_valid = 1
            OTHERS                      = 2.

  • Variable length declaration in string type

    hi all
    can anyone tell me how to declare length for string type of variables

    Hi,
    The length of a string is not static but variable and adjusts itself to the current field content at runtime. Dynamic memory management is used internally. Strings can have any length. The initial value of a string is an empty string with length 0.
    Hope this will make you clear. Please reward if answer satisfy you !!!
    Regards,
    Jignesh

  • Want to length of the string

    Hi,
    I have one parameter on the selection screen, when i enter some string on that, it should give me the length of the string. can you pls send me the code.
    Ex: if i enter : enter amount : then it should give the o/p is: 12
    Akshitha.

    use FM
    SWA_STRINGLENGTH_GET  
    enter your string in EXPRESSION and use the others if needed use "X" for all three except EXPRESSION
    EXPRESSION                      GFFHG      
    <b>CONDENSE_NO_GAPS                           
    CONDENSE                                   
    WITH_LEADING_BLANKS                        </b>
    also see STRING_LENGTH
        STRING_LENGTH
    Message was edited by:
            Amit Singla

  • Any method to find out length of a string !!

    Hello friends,
                  I used <i><b>describe</b></i> statement to find out the length of a string, but it actually returns the whole length of the string but not actual no. of char's in this.
    any one suggest a solution for this.
    Senthil

    Hi Senthil
    The ABAP function STRLEN returns the length of a string up to the last character that is not a space.
    [COMPUTE] <n> = STRLEN( <c> ).
    STRLEN processes any operand <c> as a character data type, regardless of its real type. There is no type conversion.
    As with mathematical functions, the keyword COMPUTE is optional.
    DATA: INT TYPE I,
    WORD1(20) VALUE '12345'.
          WORD2(20).
          WORD3(20) VALUE ' 4 '.
    INT = STRLEN( WORD1 ). WRITE INT.
    INT = STRLEN( WORD2 ). WRITE / INT.
    INT = STRLEN( WORD3 ). WRITE / INT.
    The results are 5 , 0, and 4 respectively.
    Regs
    vijay

  • Determining length of a string

    Hi,
    I got a string e.g strx = "abcde". Is there any function to determine the length of the string, here e.g. it would be 5?
    I appreciate any help in advance. Thanks.

    Use the length() method of the String object class
    String strx = "abcde";
    int len = strx.length();
    System.out.println(len);
    //Daniel.

  • Determining the actual length of a string based on pixels?

    How would you determine the actual length of a string based on pixels? Reason for is because a length of a string containing all " l " chars would be a lot smaller then the length of a string containing all "H" chars based on pixel width.
    thanks,
    newbie

    Yes, look at the FontMetrics class which has methods to do just that. To get a relevant FontMetrics object, try "x.getFontMetrics(f)" where x is a Component and f is the Font your string is represented in.

Maybe you are looking for

  • Difference between SY-SUBRC EQ 0 and SY-SUBRC EQ ' 0 '

    Dear All, I am not from abap background. I have a simple question. what is the difference between sy-subrc eq 0 and sy-subrc eq '0' How does it impact a statement like this for example SELECT /BIC/ZAGENT /BIC/ZBATCH_MO /BIC/ZDOC_NUM /BIC/ZCUSTOMER   

  • IOS beta 2 expired phone tells me to connect it to itunes

    Hi im a developer and I have ios 6 beta 2 on my 3gs. Unfortunatley I didnt have time or Internet to update it to 6.0; This morning I wake up and the phone is locked! Tells me to connect it to iTuens. or connect to a wifi hotspot. My wifi doesnt work

  • Exporting photos from Lightroom in their original format

    Hi all, My Lightroom library contains photos from multiple photographers. What I'd like to do is select all of a particular photographer's photos by choosing 'Creator' from the metadata browser and export the selection to a single folder. However, Li

  • Error in my logout transaction - part 3

    I guess I need a third post :/... <br /> <br />The link in the body: <br /> <br />td width="50%" align="right" valign="top"> <a href="user.account.php">Manage My Account</a> | <br /> <?php<br /> echo $tNGs->getErrorMsg();<br />?> <br /> <a href="%3C?

  • What do i do now? The licensing subsystem has failed catastrophically

    I have cs3. When I try to open any of the programs I get error message that says " the licensing subsystem has failed catastrophically. You must reinstall or call customer support."    Customer support says there is no phone support for this product