Count number of characters in a string

Another one for you experts:
Is there a way to count the number of "-" in the strings below:
For instance:
1133500-1-RTN-629-RHR
1133541-10-SRTN-F-630-LR
Should return:
4
5
respectively.
Any ideas?
Thanks in advance,
Zack H.

stringvar x := '1133541-10-SRTN-F-630-LR';
stringvar array z := split(x,'-');
ubound(z)-1;

Similar Messages

  • Method to count number of characters in a string?

    hi.
    i'm trying to write some script that will count the number of characters in a string passed into a constructor and then compare it against another value to check whether the string passed in is valid.
    something like this
    public class Stringcheck
    public static int maxStringLength;
    public static double minSize;
    public static boolean testStringLength(String x)
    // Insert method for counting number of chars in String x and name as 'int numberOfChars
    if(number of Chars <= maxStringLength )
    return true;
    else
    return false;
    can someone help me with writing this script.
    Thanks
    Richard.

    ummm, you dont need anything fancy. try:
    String test = "this is the test string";
    int length = test.length();

  • How to count number of characters in a string?

    Hi
    I need to display values in a script. but the alignment getting distrubed if it is less than 20 charaters, for exmple material descirption is only displaying 20 characters in script. if it is less than 20 charcters the alignment getting changed.
    please help me ...urgent..
    thanks in advance...

    solution to this problem in script is not to count the characters but to align them based on positions .
    1.
    Use the tab positions  for that paragraph format to display the values in a finite format .
    In this u need to give the position start and position end length and use the same in the script as
    p ,,&itab-f1&
    say my value has to print from position 125mm to 155 mm
    i take one tab position for this paragraph format P and maintain the same in the output.
    here ,, is the tab position .
    See whether it is one character or 20 character it has to behave the same way it should not be misaligned .
    check the tab position for that paragraph format in Tabs ..
    regards,
    vijay.

  • Number of characters in a string

    Hi,
    I need to find the number of characters in a string. For instance, i have a string type variable with the value "ABAP". How can i know how many letters "A" there are in that string? Is there any FM that does this?
    Cheers,
    Roberto

    Hi,
    you can make use of string operation FIND as:
    DATA: text1 TYPE string VALUE `A`,
             text TYPE string,
          off  TYPE i,
          moff TYPE i,
          mlen TYPE i.
    off = 0.
    WHILE sy-subrc = 0.
      FIND text1 IN SECTION OFFSET off OF
           `ABAP`
           MATCH OFFSET moff
           MATCH LENGTH mlen.
      IF sy-subrc = 0.
        WRITE / moff.
        off = moff + mlen.
      ENDIF.
    ENDWHILE.

  • Count number of Characters in CLOB field

    Hi all,
    I posted this on another database, but I think it really belongs here. I have a CLOB field that stores reports in HTML markup languate. Here's an example of a report.
    <br><br></title> </head> <body contenteditable="true" text="#000000" bgcolor="#ffffff"> this is a test for a bilateral modifier </body> </html><br><br>
    I'm trying to provide a query that counts the number of characters that is not a HTML tag nor whitespace. I've attempted to use a combination of the length and replace function which first replace all HTML tags and whitespaces with nothing and then uses length to calculate the number of characters. Here's what the function looks like.
    <br><br>length(trim (both ' ' from replace (replace (replace(replace (replace(replace(replace(replace (replace(replace(replace (replace(replace (replace(reports.report_text ,'</head>',''),'</title>',''),'<body contenteditable="true" text="#000000" bgcolor="#ffffff">',''),'</body>',''),'</html>',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'>','')))
    <br><br>
    For the example above, the number of characters counted in the outputs is 66, which is clearly incorrect. I need to only count these characters for the example above "thisisatestforabilateralmodifier", but there is still white space that remains after I do the sequence of replaces. If someone can help, it's be greatly appreciated. Thanks.
    Message was edited by:
    user577468

    If you can convert your html string to valid xml you can do the following:
    michaels>  SELECT str, LENGTH(REPLACE(REPLACE(XMLTYPE (str).EXTRACT ('//text()').getclobval(),CHR(10)),' ')) length
      FROM (SELECT
    '<html>
    <head>
      <title></title>
    </head>
    <body contenteditable="true" text="#000000" bgcolor="#ffffff">
       this is a test for a bilateral modifier
    </body>
    </html>' str FROM DUAL)
    STR                                                                        LENGTH
    <html>                                                                         32
    <head>                                                                         
      <title></title>                                                               
    </head>                                                                        
    <body contenteditable="true" text="#000000" bgcolor="#ffffff">                 
       this is a test for a bilateral modifier                                      
    </body>                                                                        
    </html>                                                                          Otherwise regex_replace would be an alternative (on 10g).

  • Maximum number of characters in a String?

    Does anyone know if Strings are limited to a mximum number of characters? If so, what is the limit?
    Thanks!
    Flo

    can you also tell me how Browser handle the memory aspect? AFAIK, they don't.
    All I need is a maximum of 1MB for one temporary single String.1MB should be small enough to fit in the memory... where do you get that string?

  • Return selected number of characters from a string

    How do you select a certain number of charaters from a string?
    For example:
    I have a string that contains 51-108
    I want to separate the string into two strings one containing 51 and another one containing 108.

    A StringTokenizer will do it.
    StringTokenizer strtok = new StringTokenizer(yourString, "-");

  • Looping assistance (counting number of characters in a variable)

    Good morning, all! I was wondering if anybody could take a look at this small, easy project I was working on today. I've searched the net for an answer and while it was useful and I learned a few things, nothing is really working. The code is pretty self explanatory, infact, I'm embarrassed I do not know how to do this, because I'm sure I know. Basically, counting the length of the variable is not working. The output is supposed to be as many times as the input is long in characters (I hope that makes sense!) Anyways, if you could take a look and tell me if you see anyway I could fix this, I would appreciate it.
    import java.util.*;
    import javax.swing.JOptionPane;/**
    * @author Willaim
    public class Loop {
         * @param args
         public static void main(String[] args) {
              String loopInput;
              int count;
              loopInput = JOptionPane.showInputDialog("Please enter a word for the loop demo: ");
              while(count < loopInput.length){
                   System.out.println("" +loopInput);
                   count = count + 1;
              for (count = -1; count < loopInput.length; ++count){
                        System.out.println(loopInput);
              do {System.out.println("loopInput");
                   count++;
                   }while (count < loopInput.length);
         }

    1) to get length from a String, you must use a method and all methods end in parenthesis (arrays are different in that you are getting the length field, and this doesn't require parenthesis.
    2) You probably don't want to use this "count" variable. You will probably be better with a for loop here since the number of iterations through the loop is defined in advance.
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}

  • How to count number of words in a string?

    Is it only possible by counting the number of white spaces appearing in the string?

    Of course that also depends upon how accurate you need to be and what the string contains. It is completely possible that there might be a line break which doesn't have a trailing or leading space.
    Like that.
    In that case Flash's representation of the string is likely "...space.\n\nLike that.." In chich case "space.\n\nLike" will be a word.
    Also if you split on space and there are places where there are two spaces in a row you could inflate your number. So somthing that changes newlines (and returns) to spaces, then removes any multiple spaces in a row, and finally does the split/count thing would be more accurate.
    But it all depends upon what you need.

  • How to count number of vowels in the String?

    Write a program that calculates the total number of vowels contained in the String" Event Handlers is dedicated to making your event a most memorable one."
    Please help!

    http://leepoint.net/notes/javanotes/40other/20examples/60Strings/example_countVowels.html

  • How do i return the count of matching characters in 2 string

    hi guys,
    is there any comparision function in oracle that return the number of matching character between 2 string ?
    example - 'josephine' and 'johnny'
    return 3 ('j','o' and 'n')
    please advice,
    Best Regards,
    Noob

    Hi,
    Type creation:
    CREATE TYPE t_character AS OBJECT
       v_character varchar2(1)
    CREATE TYPE characterList AS TABLE OF t_character;
    /Function creation:
    CREATE OR REPLACE FUNCTION fnc_compare_string(p_string_1 IN VARCHAR2,
                                                  p_string_2 IN VARCHAR2) RETURN VARCHAR2 IS
       RESULT  VARCHAR2(4000);
       v_list1 characterList := characterList();
       v_list2 characterList := characterList();
       v_first BOOLEAN := TRUE;
       c_separator CONSTANT VARCHAR2(1) := ',';
    BEGIN
       FOR i IN 1 .. length(p_string_1) LOOP
          v_list1.EXTEND;
          v_list1(i) := t_character(substr(p_string_1,
                                           i,
                                           1));
       END LOOP;
       FOR i IN 1 .. length(p_string_2) LOOP
          v_list2.EXTEND;
          v_list2(i) := t_character(substr(p_string_2,
                                           i,
                                           1));
       END LOOP;
       FOR reg IN (SELECT DISTINCT *
                     FROM TABLE(CAST(v_list1 AS characterList))
                   INTERSECT
                   SELECT DISTINCT * FROM TABLE(CAST(v_list2 AS characterList))) LOOP
          IF v_first THEN
             v_first := FALSE;
             RESULT  := RESULT || reg.v_character;
          ELSE
             RESULT := RESULT || c_separator || reg.v_character;
          END IF;
       END LOOP;
       RETURN(RESULT);
    END fnc_compare_string;Test:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> select fnc_compare_string('post', 'most') from dual;
    FNC_COMPARE_STRING('POST','MOS
    o,s,t
    SQL> select fnc_compare_string('post', 'jhon') from dual;
    FNC_COMPARE_STRING('POST','JHO
    o
    SQL> select fnc_compare_string('post', 'was') from dual;
    FNC_COMPARE_STRING('POST','WAS
    s
    SQL> select fnc_compare_string('post', 'w') from dual;
    FNC_COMPARE_STRING('POST','W')
    SQL> Regards,

  • Counting number of characters in a textbox

    I am keen to no, what is the best way to specify a number below a textarea, which countsdown each character entered till it reaches 0 then the user cannot enter any more characters?
    Thanks,
    Steve

    Look at some of these
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22public+void+insertstring%22+%2B%22extends+jtextfield%22+%2Bmaximum&col=javaforums

  • Finding the total size of a string when number of characters are known.

    Hi: I am having trouble inserting a field in a record that is CLOB. The number of characters in the string is 59298. Any idea how to know what is the size of this string? I am trying to figure out if I am exceeding the size of the string. The error I get is the following
    ORA-06512: at "SYS.DBMS_LOB", line 789
    ORA-06512: at line 1
    Second exception: ORA-21560: argument 2 is null, invalid, or out of range
    ORA-06512: at "SYS.DBMS_LOB", line 789
    Thanks
    Ray

    Either your stacktrace is incomplete or you make something wrong by copy/paste. And please, by providing sql/plsql code, use the tags [ code ] [ / code ] or [ pre ] [ / pre ], otherwise it is very hard to read.
    Here is small demonstration of what i mean by 3rd parameter:
    SQL> CREATE TABLE T_LOB(ID NUMBER,MESSAGE CLOB)
      2  /
    Table created.
    SQL> DECLARE
      2  l_clob CLOB;
      3  BEGIN
      4  INSERT INTO t_lob VALUES(1,'Hello')
      5  RETURNING message INTO l_clob;
      6  dbms_lob.writeappend(l_clob,length(',world'));
      7  END;
      8  /
    dbms_lob.writeappend(l_clob,length(',world'));
    ERROR at line 6:
    ORA-06550: line 6, column 1:
    PLS-00306: wrong number or types of arguments in call to 'WRITEAPPEND'
    ORA-06550: line 6, column 1:
    PL/SQL: Statement ignored
    SQL> DECLARE
      2  l_clob CLOB;
      3  BEGIN
      4  INSERT INTO t_lob VALUES(1,'Hello')
      5  RETURNING message INTO l_clob;
      6  dbms_lob.writeappend(l_clob,length(',world'),',world');
      7  END;
      8  /
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM t_lob
      2  /
            ID MESSAGE
             1 Hello,worldIn your examples, after length('some lengthy string...' there is no more parameters to dbms_lob.writeappend ( or i don't see any).
    Best regards
    Maxim

  • More on counting upper case characters

    (*This relates to a recent question I posted about counting upper case characters in a string. dev_sleidy responded with an applescript approach that works, but at 6 lines I was hoping for more compact code. So I played around with a one-line command line approach that so far seems reliable (tell me if you find it isn't). However, there are a couple peculiarities which I would like to understand. I know, I know, I should just shut up and use it. But I must be part cat and need to be killed.
    The code that appears to work:*)
    set T to "MY GraNd QuestioN A"
    set UCcount to do shell script "echo " & quoted form of T & " | tr -d [[:space:]] | tr -d [:lower:] | wc -m"
    (*The peculiarities:
    1) If I substitute >>sed 's/ //g'<< for >>tr -d [[:space:]]<<, the result always seems to be one count high. (Same thing appears to happen when executed in Terminal.) Why?
    2) When using regular expressions the format [[:class:]] has always worked for me, as it does for "space" in the code above. But for the second tr -d pipe (above code) those outside brackets mess everything up, and single brackets work fine. Same thing happens with both [[:lower:]] and [[:upper:]] but doesn't seem to happen when executed in Terminal. Why? Are there rules for bracketing character classes (I've seen different versions)?
    Or is all this a UNIX forum question?*)

    Hello
    Honestly I don't understand why such result is returned by CODE1.
    Its prototype [1] tested here works as expected.
    But I noticed CODE2 may return wrong result, for its prototype [2] actually returns wrong result with MacPerl 5.6.1r2 under OS9.1 when input string is read from file insead of being given as string literal. I didn't test that possibility. Sorry for that. Please disregard CODE2, for I think CODE1 will be enough.
    (The wrong result is caused by the fact that 'Ç' encoded in UTF-8 is counted as 2 chararcters by length function if it is read from file due to certain limitation of MacPerl 5.6.1r2. I don't know whether that applies to recent Perl under OSX.)
    [1]
    use utf8;
    while (<>){
    s/[^[:upper:]]//g;
    } continue {
    print;
    [2]
    use utf8;
    local $/;
    while (<>){
    s/[^[:upper:]]//g;
    print length;
    Re. your original question about peculiarities.
    As for 1), I think it is because 'echo' is adding trailing \n and "sed 's/ //g'" won't remove it. Try "sed 's/[[:space:]]//g'"  instead. Indeed "sed 's/[^[:upper:]]//g' will remove all non-upper case letters at once, I guess.
    As for 2), I think it is because 'tr' actually does not process regexp. Its character class support is based upon POSIX but the usage is different from regexp, i.e. [:class:] in 'tr', while [[:class:]] in proper regexp. Meanwhile, I think, the regexp syntax, [[:class:]], in 'tr' argument works in Terminal because in Terminal, 'bash' processes the regexp in its parameter expansion (path name expansion, in this case) and 'tr' receives the expanded result as its argument.
    cf.
    http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/tr.1.htm l
    http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/bash.1.h tml
    Hope this may be of some help,
    H

  • How to count number of repeated characters in a String

    I have a String.... 10022002202222.
    I need to know how many 2's are there in the string... here the string contains eight 2's..
    Thanks in advance..

    it is workingYes, but... attention to surprises...
    SQL> var v1 varchar2(1000);
    SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
                                       6
    SQL> exec :v1 := 'cccccc';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
    SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
    LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
                                              6
    SQL>

Maybe you are looking for

  • How to charge my Itouch with laptop

    hi peoples, just bought the iTouch today, naughty piece of kit. but i know when you get it....it needs a good 12 or so hours charge....am i right....? if so i have a laptop and cant really leave that on with it charging as i dont have a mains charger

  • Return Delivery docuent cancel

    Dear Experts We have one problem regarding Return delivery through QA32 We have done 'Return Delivery' from QA32 T Code But Now accounting department cannot MIRO for the same GR document number Henceforth when trying to cancel return delivery documen

  • Excel to SAP

    Hi Experts, I am having one excel file and in that excel file i am having 5 sheets. I want to transfer 3rd sheet data into excel. How its possible please give some solution its very urgent... Rajneesh

  • Things to taken into account  with Flex 3 Modular Programming approach

    Hi , I am new to Flex , using currently Flex 3 for Programming . Till now i am developing simple  Applications , (Simple in the sense one Application mxmxl file and some Custom Components), i am able to do this with the help of expert  people in Adob

  • Photoshop CS5 doesn't have same printer presets as other CS5 products

    I am trying to print from Photoshop CS5 to a Konica Bizhub c451 printer that uses account tracking and user authentication.  But, when attempting to print from photoshop CS5 the printer preset doesn't have the same options (doesn't allow us to put in