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.

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();

  • 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, "-");

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

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

  • 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

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

  • How to find number of characters in a character string

    Hi,
      Can anyone please tell me about how to find the number of characters in a character string type variable.
    Reagards,
    Siva

    hi,
    Use STRLEN for Calculating String Length..
    Assign it to integer variable for Further Use.Suppse u need to find string length for "hai".. this piece of code will help u
    data:  var type string value 'hai',
             len type i.
    len = strlen(var).
    write len.

  • Maximum number of characters for a BPEL string variable

    Hi,
    What is the maximum numbers of characters that a string variable in BPEL process can hold??.
    Is there any document which describes the datatypes in BPEL.
    Regards
    V Kumar

    Trick question - with or without the use of the FM GUI?
    1. Via the FM interface to define a variable, FM will only save the first 1022 characters of your variable definition - if you dare try to enter that many via the GUI dialogue slot.
    2. Importing a variable via MIF, adds virtually any length - I've tested out 2510 characters. HOWEVER, FM will only display the first 1023 characters of this string.
    If you save the file to MIF, you can still see the original length of the variable. The other caveat is that if you touch any of these long variables via the FM GUI (Edit Variables), then FM will truncate it down to 1022 characters - regardless of how you save (binary or MIF).
    FWIW - Klaus Daube lists (see: http://daube.ch/docu/fmaker25.html ):
    Until FM 7.2: up to 255 characters including meta-notations (such as <Default ¶ Font> or \t - this counts as 16 resp. 2 characters). See also note Variables below
    From FM 8.0: up to 2023 Windows Codepage characters or up to 2022 UTF-8 characters
    I'd say that this is not quite correct. You could enter more than 255 prior to FM 7.2 as well, but again the display issue via the GUI kicked in and truncated down to 255. The newer versions only display 1022/1023 but you can enter more than 2510 characters (which in this case is futile anyway).

  • Removing number of characters from end of string

    Hi all....
    Dooza very kindly helped me with trimming a string in an
    earlier post, but
    now i want to remove the last four characters from a string.
    I really should know how to do this and will have to do some
    bedtime reading
    :-|
    But, for now, could someone help!
    Thanks
    Andy

    Ah Dooza - Thank You.
    To the rescue again :-D
    You're helping me to see the logic...
    Thanks Again
    Andy
    "Dooza" <[email protected]> wrote in message
    news:gbafel$ra3$[email protected]..
    > Andy wrote:
    >> Hi all....
    >> Dooza very kindly helped me with trimming a string
    in an earlier post,
    >> but now i want to remove the last four characters
    from a string.
    >> I really should know how to do this and will have to
    do some bedtime
    >> reading :-|
    >>
    >> But, for now, could someone help!
    >
    > Hi Andy,
    > Try something like this:
    > <%
    > myStr = "this is my really long string"
    > Response.Write(LEFT(myStr,LEN(myStr) -4))
    > %>
    >
    > Dooza

  • How do I limit number of characters in a JTextField?(different from others)

    Hi,
    I know this question has been posted several times on this forum, but my question is actually a different one. So please read.
    I have the following code that puts two JTextFields in a JFrame. I want to limit the number of characters in the first JTextField to three characters. What's different about my question from other solutions provided, is that I don't want to be able to type more than three characters in the JTextField, and then not be able to get out of JTextField unless I have three or less characters. What I do want, is to have maximum of three characters, not be able to type the fourth, and have access to the other JTextField at all times.
    I have tried the following solution of setting an InputVerifier to my JTextField, but it hasn't worked, since I can still type the fourth character.
    Looking forward to your help!
    Thanks.
    import java.awt.Dimension;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.InputVerifier;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class TextFieldVerifier {
         public TextFieldVerifier()
              JFrame frame = new JFrame("My TextVerifier");
              JPanel panel = new JPanel();
              JLabel firstTextFieldLabel = new JLabel("First: ");
              JLabel secondTextFieldLabel = new JLabel("Second: ");
              final JTextField myTextField = new JTextField();
              myTextField.setPreferredSize(new Dimension(100,20));
              myTextField.setInputVerifier(new InputVerifier()
                   public boolean verify(JComponent input) {
                        if(myTextField.getText().length()<=3)
                             return true;
                        else
                            return false;     
              myTextField.addKeyListener(new KeyAdapter()
                   public void keyTyped(KeyEvent e)
                        if(!myTextField.getInputVerifier().verify(myTextField))
                             myTextField.setText(myTextField.getText().substring(0, myTextField.getText().length()-1));
              JTextField secondTextField = new JTextField();
              secondTextField.setPreferredSize(new Dimension(100,20));
              panel.add(firstTextFieldLabel);
              panel.add(myTextField);
              panel.add(secondTextFieldLabel);
              panel.add(secondTextField);
              frame.getContentPane().add(panel);
              frame.setSize(new Dimension(200,100));
              frame.setVisible(true);
         public static void main (String [] args)
              TextFieldVerifier v = new TextFieldVerifier();
    }

    Thanks, JayDS! Your suggestion worked. And I've come up with the following code with help of your suggestion. However, I'm not happy with the fact that I see empty spaces in my JFormattedTextField when I don't have anything entered in it, or when my textfield has focus and I click it again. Also, I'd like the text alignment to always stay on the right, even if I have less than 3 digits.
    Could you please help me out with that?
    Thanks!
    import java.awt.Dimension;
    import java.text.ParseException;
    import javax.swing.JFormattedTextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.text.MaskFormatter;
    public class TextFieldVerifier {
         public TextFieldVerifier()
              JFrame frame = new JFrame("My TextVerifier");
              JPanel panel = new JPanel();
              JLabel firstTextFieldLabel = new JLabel("First: ");
              JLabel secondTextFieldLabel = new JLabel("Second: ");
              try{
                   VariableLengthMaskFormatter formatter = new VariableLengthMaskFormatter("###");
                   final JFormattedTextField myTextField = new JFormattedTextField(formatter);
                   myTextField.setHorizontalAlignment(JTextField.RIGHT);
                   myTextField.setPreferredSize(new Dimension(100,20));
                   panel.add(firstTextFieldLabel);
                   panel.add(myTextField);
              } catch (ParseException ex) {
                   ex.printStackTrace();
              JTextField secondTextField = new JTextField();
              secondTextField.setPreferredSize(new Dimension(100,20));
              panel.add(secondTextFieldLabel);
              panel.add(secondTextField);
              frame.getContentPane().add(panel);
              frame.setSize(new Dimension(200,100));
              frame.setVisible(true);
         protected MaskFormatter createFormatter(String s) {
             MaskFormatter formatter = null;
             try {
                  formatter = new MaskFormatter(s);
             } catch (java.text.ParseException exc) {
                 System.err.println("formatter is bad: " + exc.getMessage());
                 System.exit(-1);
             return formatter;
         public static void main (String [] args)
              TextFieldVerifier v = new TextFieldVerifier();
    }Edited by: programmer_girl on Mar 10, 2008 11:10 PM

  • Coding - returning the number of characters in a text box.

    I am in the process of creating a cell phone simulation/animation in Edge Animate CC for use in a Captivate course. Basically, when a user clicks on number buttons on the virtual keypad, it displays the numbers in a text box , just like an actual cell phone would display the phone number on the screen as a caller is dialing. So, the user would click seven buttons and a seven-digit phone number appears on the virtual phone screen.  This part of my animation works great and all seven digits appear, but I would like to modify the code so that a hyphen appears after the third button clicked. This way, the output better resembles an actual phone number instead of just a string of seven digits.
    Here is an example of the code I currently have assigned to the #2 button on the virtual keypad:
    var text = sym.$("PhoneNum").html();
    text = text + 2;
    sym.$("PhoneNum").html(text);
    PhoneNum is the name of my text box on the stage where the digits appear as each keypad button is clicked.
    In order to incorporate the hyphen after the third button clicked, I need to somehow return the current number of characters in the PhoneNum text box, then create an if/else scenario that applies the hyphen after the third button clicked.
    Does anyone know how I can use either JavaScript or jQuery to return the number of characters currently in the PhoneNum text box?

    No problem!
    Basically the thing to remember is that unless you are needing to pass html to the object, you can use text() instead. text() also gives you the raw text without any html formatting (so you can assume what .html() would return)

  • What is the maximum number of characters in an Oracle 10G Instance Name

    All,
    Can I know what is the maximum number of characters in an oracle 10g instance name under AIX? Is it 7 characters or 8 characters?
    regards
    Santhosh

    One should really make the difference between db_name and instance_name: if instance_name default value is db_name it can be different
    (even on a non RAC database).
    For example with Oracle 10.2.0.4 you can create a database named DB78 with instance_name=DB12345678:
    $ uname -a
    Linux lx01.localdomain 2.6.18-92.el5 #1 SMP Fri May 23 22:17:30 EDT 2008 i686 i686 i386 GNU/Linux
    $ ps -fu oracle | grep smon
    oracle    6353     1  0 20:30 ?        00:00:01 ora_smon_DB12345678
    oracle    6412  5596  0 20:37 pts/1    00:00:00 grep smon
    $ export ORACLE_SID=DB12345678
    $ sqlplus / as sysdba
    SQL*Plus: Release 10.2.0.4.0 - Production on Wed Sep 8 20:34:26 2010
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> show parameter name
    NAME                                 TYPE        VALUE
    db_file_name_convert                 string
    db_name                              string      DB78
    db_unique_name                       string      DB78
    global_names                         boolean     FALSE
    instance_name                        string      DB12345678
    lock_name_space                      string
    log_file_name_convert                string
    service_names                        string      DB78I would not recommend this practice: but it's interesting to know to avoid confusing between db_name and instance_name.

  • Unable to read more than 255 characters in a string data type.

    Hello,
    I am using Crystal Reports version 11.5.8.826 to generate reports from databases such as MS-Excel & BaaN.
    In Excel, there are records which carry string lengths of more than 255 characters. All though the fields are getting displayed in the report, the data being displayed gets truncated once it reaches a length of 255 characters.
    Kindly provide me with a solution this problem.
    Regards

    Hello Manish,
    I know that older versions of Crystal (Crystal 10 and older ) had a limitation of only 256 Characters for a string value.  You should be able to use this code to get what  you need. 
    We were successfully able to print out the Declaration of Independence through a Crystal report using something very similiar to this.
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    Shared StringVar Array strings;
    Shared NumberVar arrayMax := 1;
    Shared NumberVar maxLength := 250;
    Shared BooleanVar firstTime := true;
    Redim strings[arrayMax];
    strings[1] := u201Cu201D;
    u2018done!u2019
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    Here is my main loop that I used in the group header:
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    WhilePrintingRecords;
    Shared StringVar Array strings;
    Shared NumberVar arrayMax;
    Shared NumberVar maxLength;
    Shared BooleanVar firstTime;
    Local StringVar enteredString;
    Local NumberVar lenStr;
    Local NumberVar lenArr;
    Local NumberVar lenLeft;
    enteredString := [Field Name];
    enteredString := IIF(firstTime,enteredString, u201C, u201D & enteredString);
    firstTime := false;
    lenStr := Length(enteredString);
    lenArr := Length(strings[arrayMax]);
    lenLeft := maxLength u2013 lenArr;
    if (lenLeft >= lenStr) then
    strings[arrayMax] := strings[arrayMax] & enteredString;
    u201D
    else
    strings[arrayMax] := strings[arrayMax] & left(enteredString, lenLeft);
    arrayMax := arrayMax + 1;
    redim preserve strings[arrayMax];
    strings[arrayMax] := u201Cu201D;
    strings[arrayMax] := strings[arrayMax] & right(enteredString, lenStr u2013 lenLeft);
    u201D
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    and then to display the different sets in the text area. I would have one of these for every element I need displayed and change the display number variable.
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    Shared StringVar Array strings;
    Shared NumberVar arrayMax;
    Local NumberVar displayNumber := [element in array];
    if(arrayMax >= displayNumber) then
    strings[displayNumber];
    else
    u201D;
    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
    I like this version better because the array is completely dynamic. It can be as big or as small as it needs to be.  There is always room for optimizations.  But hopefully this will get you started on the right path.
    Jenny

Maybe you are looking for

  • Audio recorded too high - can I change

    I'm doing a slideshow for my daughter's cheer banquet & found that some of the video clips that I am using is at high levels and you can hear a high pitched sound - can I get rid of the high pitched sound (kinda like a stereo that is played too loud

  • VOD outage - steaming mad

    Thanks for ruining my weekend Verizon!  Been trying to watch VOD movies but no, it's not working. Are you serious? I cannot believe how much $ I pay Verizon every month for lousy service and non-existent customer service.  I'm going back to Direct TV

  • Imp with STREAMS_INSTANTIATION=y takes too long...

    Dear All, I am in process of implementing streams between 2 10gR2 databases on Linux. During this process i noticed that imp command on the target database with these parameters takes so long... imp userid=bill/till fromuser=bill touser=bill FILE=/tm

  • Poor Image Quality on Finished Project

    I've seen similar questions before, but no responses. I put together a movie using still pictures, titles, and audio from iTunes using iMovie. I then export it to a .m4v format and import it into iDVD (the newest version). It looks perfect when I vie

  • Where do i get my itunes back up password

    I am trying to set up my new phone and need to hook up to itunes but it is asking for my itunes back up password and I cant remember. There is no place to click on "forgot password". Also, I was almost out of memor and would like to restore everythin