Scanning values of characters in a string

Hey guys,
I'm trying to figure out a way I can scan the individual characters of a string to find their value [unicode value, if it's a number, punctuation etc] and I'm a bit stumped. I know I'll have to be using the chatAt method, but I can't think of how I could implement this to continuiously scan through a string.
If someone could help point me in the right direction it would be great.
Thanks in advance.

Do you know what a loop is?
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html
Do you know how to find out about methods of the String class such as toCharArray?
http://java.sun.com/javase/6/docs/api/java/lang/String.html

Similar Messages

  • Need help in replacing special characters in a string

    Hi,
    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    with regards.
    sumanth.

    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    >
    Sumanth Nag Kristam wrote:
    > actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart
    > any pointers....
    >
    > chk the link for the ASCII codes
    > http://www.techonthenet.com/ascii/chart.php
    But in Hexa decimal value there is no special characters?

  • Sample code to identify special characters in a string

    Hi,
    I need to identify special characters in a string.... could anybody send me some code please.......
    Thanks,
    Best regards,
    Karen

    data: str(100) type c.
    data: str_n type string.
    data: str_c type string.
    data: len type i.
    data: ofst type i.
    str = '#ABCD%'.
    len = strlen( str ).
    do.
      if ofst = len.
        exit.
      endif.
      if str+ofst(1) co sy-abcde.
        concatenate str_c str+ofst(1) into str_c.
      else.
        concatenate str_n str+ofst(1) into str_n.
      endif.
      ofst = ofst + 1.
    enddo.
    write:/ str.
    write:/ str_c.
    write:/ 'spacial chracter',20 str_n.
    Function module  <b>SF_SPECIALCHAR_DELETE</b> <b>DX_SEARCH_STRING</b>
    l_address1 = i_adrc-street.
    CHECK NOT L_ADDRESS1 IS INITIAL.
    len = STRLEN( l_address1 ).
    do len times.
    if not l_address1+l(1) ca
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 '.
    if i_adrc-street+l(1) CO sy-abcde.
    elseif i_adrc-street+l(1) CO L_NUMCHAR.
    exit.
    endif.
    l = l + 1.
    enddo.
    data : spchar(40) type c value '~!@#$$%^&()?...'etc.
    data :gv_char .
    data:inp(20) type c.
    take the string length .
    len = strlen (i/p).
    do len times
    MOVE FNAME+T(1) TO GV_CHAR.
    IF gv_char CA spchar.
    MOVE fnameT(1) TO inp2T(1).
    ENDIF.
    T = T + 1.
    enddo.
    REPORT ZEX4 .
    PARAMETERS: fname LIKE rlgrap-filename .
    DATA: len TYPE i,
    T TYPE I VALUE 0,
    inp(20) TYPE C,
    inp1(20) type c,
    inp2(20) type c,
    inp3(20) type c.
    DATA :gv_char.
    data : spchar(20) type c value '#$%^&*()_+`~'.
    START-OF-SELECTION.
    CONDENSE fname.
    len = strlen( fname ).
    WRITE:/ len.
    DO len TIMES.
    MOVE FNAME+T(1) TO GV_CHAR.
    IF gv_char ca spchar.
    MOVE fnameT(1) TO inpT(1).
    ENDIF.
    T = T + 1.
    ENDDO.
    CONDENSE INP.
    write:/ 'Special Characters :', inp.
    Rewards if useful..........
    Minal

  • 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

  • Is there a limitation of characters in a String variable in 8.0.2?

    Is there a limitation of characters in a String variable?
    I'm trying to create an email within my script and when I paste my text into my parameter, which is a String variable, it will only paste up to 80 characters (including spaces).
    In 7.0 I was able to paste my paragraphs and the larges paragraph had 346 characters (including spaces).
    Thanks,
    Debbie

    Greg,
    Ah.... that's it. 
    I modified the value of the parameter within the script and added the text that I needed. I added the following:
    "To transfer the file over to the router's flash you will need an TFTP or FTP program.  Start your application and make sure that the default directory is pointed to the directory where you copied the greeting.  Now log into the router that needs to be updated.  Once you are in the router issue one of these commands:"
    It accepted it and was able to use the entire value.  So it must be the web page that will not allow me to enter more then 40 characters.
    Do I need to get this submitted as a bug?
    Thank you,
    Debbie

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

  • How do I convert the ASCII character % which is 25h to a hex number. I've tried using the scan value VI but get a zero in the value field.

    How do I convert the ASCII character % ,which is 25h, to a hex number 25h. I've tried using the scan value VI but I get a zero in the value field. 

    You can use String to Byte Array for this.

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

  • Ascii value of a non numeric string  literal

    hi,
    i would like to get the ascii value of a non numeric string
    having special characters from extended ascii set.
    for example i have a user id "J��o M��" and i want to get the ascii value of each character in this string.
    (There are special characters having ascii value more than 127, present in string literal)
    if you know some methods to do that ??
    thanks

    Use charAt(i) to give you each char in the string. A char is also the numeric value of the character: note that there's no such thing as "extended ASCII" -- ASCII is the first 128 characters of Unicode, and Java uses Unicode characters.
    String str = "Hello";
    for (int i = 0; i < str.length(); i++)
        System.out.println((int) str.charAt(i)); // cast to int so the char is displayed as a number

  • Specify characters in a string

    I'm a beginner at Java.
    I need to create a program that will validate only binary characters in a string and count the number of 0s in the string. For some reason I keep getting an error message. For the life of me, I can't figure it out.
    char a = '1';
    char b = '0';
    int hmo;
    int totalzeroes=0;
    String input = JOptionPane.showInputDialog(null, "Please Enter a Binary Number");
    for (hmo=0; hmo<input.charAt(hmo);hmo++)
    System.out.println(input.charAt(hmo));
    totalzeroes++;
    OUTPUT:
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range:
         at java.lang.String.charAt(Unknown Source)
         at cop.main(cop.java:19)

    ...hmo<input.charAt(hmo)...You have to loop up to input.length(), not to the value of the character at certain position.
    Mike

  • Trim last two characters of a String

    Hi,
    I have a task to trim the last two characters of a string in a column and get the rest as output for comparison purpose.
    the length of column value is not fixed.
    For example
    I/p O/p
    India_1 India
    America_2 America
    I achieved the result using the below query:
    SELECT SUBSTR (TRIM ('India_1'), 1, LENGTH (TRIM ('India_1')) - 2) FROM DUAL;
    I have used the trim function to remove the leading and trailing spaces in the column value.
    Could somebody please let me know if there is a better way to get the result .. like in one shot query.
    Thanks,
    Pratik

    I have a task to trim the last two characters of a string in a column
    SQL> with t as (
    select 'India_1' str from dual union all
    select 'America_2' from dual
    select regexp_replace(str, '..$') str1 from t
    STR1        
    India       
    America     
    2 rows selected.

  • How to replace the char values into numeric in my string?

    Hi Friends,
    I would like to Replace the Charecter values with numeric value in my string.
    Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
    I mean How to replace the char values into numeric in my string?
    Thanks,
    Sridhar

    Hi Sridhar,
    I would like to Replace the Charecter values with numeric value in my string.
    Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
    So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
    DATA: l_str TYPE string.
    l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
    REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
    IF sy-subrc EQ 0.
      WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
    ENDIF.
    Regards,
    Chen
    Edited by: Chen K V on Jun 13, 2011 12:36 PM

  • How many characters can a String hold?

    How many characters can a string hold, and can i give the value of a JTextArea to a string? Thanks -

    well, you could try it, it should only take a few lines of code to see how large a String can get.
    I think a String can be larger than the text of a JTextArea, not sure though.

  • Extracting the n-th value with "scan value"

    Is it possible to use scan value to extract the second, third etc. value from a string?
    example:
    string: 3.14+5.0
    and I want to get 5.0 without knowing the value 3.14 - is that possible ? if yes - how to do that ??

    Using your example, using a format string of %f+%f should do the trick. See the attachment.
    Attachments:
    scan_from_string.jpg ‏5 KB

  • 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