Reg: Replacement of second occurance of character in string

Hi,
Consider one string1 =  'ABCDAE' OR  string2 = 'SHEETAL'.
I want to replace the second occurance of A in above string1.and second occurance of E in above string2 with any differnt character.
I tried with offset calculation , length , replace , split stmts.
but always first occurance is getting replace.
Please provide your ideas.
Regards,
Shital

Hi,
Try this.
data: string1 type char10 value 'ABCDAE',
        len     type i.
  write: / string1.
  search string1 for 'A'.
  if sy-subrc = 0.
    add 1 to sy-fdpos.
    len = strlen( string1 ) - sy-fdpos.
    replace 'A' in string1+sy-fdpos(len) with '!'.
    write: / string1.
  endif.
Darren

Similar Messages

  • Search and replace, everey second character?

    I'm making a VI that is communicating with an external device through a protocol built up of frames. I have made a couple of subVIs that put these frames together as hexadecimal strings that are then converted into numbers and passed on to the device. The protocol uses an escape character in order to avoid sending an BOF or EOF constant at the wrong time. I've made a subVI that is supposed to do this using the Serch and Replace function. At first it seems rather elegant, but it has a fatal flaw, if one of the characters it is supposed to hide is written across the edge of a byte, it will still be replaced.
    Example:
    11 01 00 EC 0D EA 05 08
    is replaced by
    11 01 00 E7 DE 0D EA 05 08
    C0, C1, 7D are the characters to be replaced, 7D is the escape character.
    Now I wonder, is it possible to make the search and replace function search only every second character in a string?
    Solved!
    Go to Solution.
    Attachments:
    Insert_Escape_Characters.vi ‏10 KB

    Hi,
    I'm not sure to understand your problem, but I propose this solution !
    Hope it helps you.
    Best regards,
    Vincent
    Message Edité par ramses64 le 02-20-2009 03:57 AM
    V-F
    Attachments:
    replace.PNG ‏17 KB

  • Error occurred during character conversion in SXMB_MONI

    Hello Experts,
    Good Day!
    I would like to seek your help here. When i used tcode SXMB_MONI to search for messages i get this error : Error occurred during character conversion.
    So far no problem with the program. Its work for all other dates. Just for one particular day and specific time period, im geting this error.
    Does anyone know what is this error means? Please reply..
    Thanks for your help.
    Looking forward for ur replies..

    Hi Presheela,
    Basically this problem occurs when ur payload contains any special characters like '&' ,'>'...etc .So you have to take care of how to deal with these characters in XI.
    Refer the following documentation:
    How to Work with Character Encodings in Process Integration
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
    Regards,
    Vinod.

  • Replacing all occurrences of characters in a string with one new character?

    Hi there,
    I'm looking for a way that I could replace all occurrences of a set of specific characters with just one new character for each occurrence.
    For example if I have a string which is "word1...word2.......word3....word4............word5" how would I be able to replace this with just one character such as ":" for each set of "." so that it would essentially appear like this "word1:word2:word3:word4:word5"
    If I just use replace(".", ":") I am left with "word1:::word2:::::::word4::::word5::::::::::::"
    So therefore I'm guessing this would require the use of replaceAll() maybe? but I'm not really very familiar with how regular expressions work and how this would be accomplished using them.
    Any help would be greatly appreciated :) Thanks.

    Yes, but "." means any character, so ".\+" means "any character repeated more than once". If you just mean a full stop ("period" for you Americans :p) you should use "\.+" as your regular expression, but remember that for Java you need a '\' escape to recognise '\' as '\', so in code you'd actually type your regex as:
    "\\.+"Here's an example of one way to do it:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test {
        public static void main(String[] args) {
           String string = "example1.......example2...example3.....example4";
         Pattern pattern = Pattern.compile("\\.+");
         Matcher stringMatcher = pattern.matcher(string);
         string = stringMatcher.replaceAll(":");
         System.out.println(string);
    }Edited by: JohnGraham on Oct 24, 2008 5:19 AM
    Edited by: JohnGraham on Oct 24, 2008 5:22 AM

  • SMQ2 (Inbound Queue) : Error occurred during character conversion

    Hi,
    In SMQ2 an Inbound Queue has failed with status text "Error occurred during character conversion". The XML message inside this queue is in waiting status with status text " Scheduled for Outbound Processing" .
    Even after cancelling this message from SXMB_MONI, and reposting the PO, still again the queue and the XML message inside the queue are in same status.
    As this is in XI production system, requesting to provide some suggestion ASAP.
    Thanks,
    Mateen.

    The queue status is still sysfail. There is only 1 message waiting in the queue.
    I think that the queue might be locked for some reason and after unlocking the queue and restarting the message, the message will get processed successfully.
    But before working on this I want to make sure that the queue is locked.
    Do you or anyone else know how and from where can I check whether the queue is locked or unlocked?
    Regards,
    Mateen.

  • Replace any occurence of a character in a varchar2 column

    What would be the best way to replace any occurence of a character in a column (varchar2) of a table?
    Lets say we want to replace any occurence of the character ~ by the character & in the column c1 of the table t.
    Is it possible in pure SQL?
    I did it in PL/SQL in a while loop but I am pretty sure there is a way to do that in a single SQL statement. Am I right on wrong?
    Thanks
    Best regards,
    Carl

    The Ampersand has a special meaning in SQL to mark a variable.
    That's why you need to set 'scan off' or 'define off' or
    For more information see here
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm#1012408
    set scan off
    update t
    set c1=replace(c1, '~', '&');

  • Finding Second occurance of a String

    Hi All,
    How can find the second occurance of a string in text.
    Is there any way to find that using contains string?
    Thanks in Advance
    Regards,
    Raghu

    Hi,
    <b>Check the sample coding done below using CS contains String operator</b>
    DATA: str TYPE string VALUE 'testing the test'.
    DATA: sub type string value 'test'.
    DATA: tempstr TYPE string.
    DATA: len TYPE i.
    DATA: rem_len type i.
    IF str CS sub.
      len = STRLEN( sub ) + sy-fdpos.
      rem_len = STRLEN( str ) - len.
      tempstr = str+len(rem_len).
    ENDIF.
    WRITE: tempstr.
    if tempstr CS sub.
    write: sy-fdpos. " This is the second occurances offset
    endif.
    Regards,
    Sesh

  • Timeout(60 seconds) occurred waiting for page to load

    Hello,
    Can somebody provide solution for mentioned problem-
    After Browser launch when I try to navigate the URL, openscript is throwing error (Timeout(60 seconds) occurred waiting for page to load.).
    Error code - WAIT_FOR_PAGE_TIMEOUT_ERROR.
    I am performing following steps.
    1. Launch Browser
    2. Navigate to Oracle EBS url
    3. Close Browser
    4. Launch Browser
    5. Navigate again to Oracle EBS url
    The last steps is not working correctly, openscript throw timeout error and also IE msg "Internet Explorer has stopped working".
    IE version - 8
    Thanks.

    Any comments plz

  • Java.lang.String:   How can we replace the list of characters in a String?

    String s = "abc$d!efg:i";
    s = s.replace('=', ' ');
    s = s.replace(':', ' ');
    s = s.replace('$', ' ');
    s = s.replace('!', ' ');
    I want to check a list of illegal characters(Ex: $ = : ! ) present in the String 's' and replace all the occurance with empty space ' '
    I feel difficult to follow the above code style.. Because, If list of illegal characters increased, need to add the code again to check & replace the respective illegal character.
    Can we refactor the above code with any other simple way?
    Is there any other way to use Map/Set in this above example?

    RTFM
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
    That document is almost perfectly useless for someone
    who is just starting to learn regexes. What they
    need is a good tutorial, and the best one I know of
    for Java programmers is the one at
    this site. When you're ready to move on from
    introductory tutorials, get the latest edition of
    Mastering Regular Expressions, by Jeffrey Friedl.Dear Uncle,
    maybe you want to read that document first before judging its usefulness. And just in case you can't be bothered, the following is an exact quote, which accidently happens to clearly explain the op's question on the usage of \\[\\] in sabre's regex:
    Backslashes, escapes, and quoting
    The backslash character ('\') serves to introduce escaped constructs, as defined in the table above, as well as to quote characters that otherwise would be interpreted as unescaped constructs. Thus the expression \\ matches a single backslash and \{ matches a left brace.
    It is an error to use a backslash prior to any alphabetic character that does not denote an escaped construct; these are reserved for future extensions to the regular-expression language. A backslash may be used prior to a non-alphabetic character regardless of whether that character is part of an unescaped construct.
    Backslashes within string literals in Java source code are interpreted as required by the Java Language Specification as either Unicode escapes or other character escapes. It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler. The string literal "\b", for example, matches a single backspace character when interpreted as a regular expression, while "\\b" matches a word boundary. The string literal "\(hello\)" is illegal and leads to a compile-time error; in order to match the string (hello) the string literal "\\(hello\\)" must be used.

  • Error 1 occurred at Scan From String (arg 1)

    I am communicating with the AT Trainer 5000 via serial port to USB converter.
    I installed all drivers of converter successfully and it is shown in MAX as com port. I also installed VISA software. 
    I am using labview 2013 version.
    When I connect the hardware to PC via usb to serial converter, try to run the program for seeing of real time graphs, I am receiving this error Error 1 occurred at Scan From String (arg 1) whereas there is no waveform shown in waveform chart. 
    Also read buffer didn't show an incoming data at read buffer.
    Other details for this error is
    Possible reason(s):
    LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
    Also pics of error is:
    Program is also attached. Please checked the also.
    Expert please help me how to get rid of this error.
    Attachments:
    Project.vi ‏23 KB

    Since you are using the termination character, you should not use the Bytes At Port property node.  Just set the number of bytes to read for the VISA Read to something really high (larger than what you expect in a single transmission).  The VISA Read will stop reading once the termination character is reached.
    Now, what is the format of the data coming from the instrument?  I see you are converting an ASCII Hex string into a number while trying to also turn it into a double.  That is likely why you are getting your error.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions

  • Please help, urgently Error 1 occurred at Scan From String (arg 1).

    I am communicating with the AT Trainer 5000 via serial port to USB converter.
    I installed all drivers of converter successfully and it is shown in MAX as com port. I also installed VISA software. 
    I am using labview 2013 version.
    When I connect the hardware to PC via usb to serial converter, try to run the program for seeing of real time graphs, I am receiving this error Error 1 occurred at Scan From String (arg 1) whereas there is no waveform shown in waveform chart. 
    Also read buffer didn't show an incoming data at read buffer.
    Other details for this error is
    Possible reason(s):
    LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
    Also pics of error is:
    Program is also attached. Please checked the also.
    Expert please help me how to get rid of this error.
    Attachments:
    Project.vi ‏23 KB

    duplicate post http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/Error-1-occurred-at-Scan-From-String-arg-1/td...

  • How to replace multiple occurences of space in a string to a single space?

    How to replace multiple occurences of space in a string to a single space?

    Hi,
    try this code.
    data : string1(50) type c,
              flag(1) type c,
              dummy(50) type c,
              i type i,
              len type i.
    string1 = 'HI  READ    THIS'.
    len = strlen( string1 ).
    do len times.
    if string1+i(1) = ' '.
    flag = 'X'.
    else.
    if flag = 'X'.
    concatenate dummy string1+i(1) into dummy separated by space.
    clear flag.
    else.
    concatenate dummy string1+i(1) into dummy.
    endif.
    endif.
    i = i + 1.
    enddo.
    write : / string1.
    write : / dummy.

  • Save Query - An error occurred while creating connection strings for the query

    A workbook trying to edit and reload I get the following error "Save Query - An error occurred while creating connection strings for the query" No Power Pivot data model or anything.

    I am getting the same error when editing a Power Query in an Excel spreadsheet. It happens when I change a Group By step to do a Sum instead of Count Rows.

  • Replace all occurrences of ENTER in a string

    Hi,
    I have a string which contains line breaks:
    '<HTML><HEAD>
    </HEAD>
    <BODY>'
    and it is shown to me in the debugger as:
    '<HTML><HEAD>#</HEAD>#<BODY>'
    Now I want to replace all line breaks in the string,
    but
    replace all occurrences of `#` in text with ' '.
    doesn't work.
    So if you have an idea how to replace the # symbol for Enter in a string please tell me ;).
    regards,
    Stefan

    Hi,
    Pls use
    replace all occurences of '#' in text with cl_abap_char_utilities=>newline.
    Eddy

  • AES256 bit encyption key from 64 character long string

    Hi,
    I have Oracle 10.2 on Windows 2003. I have recently started working on a project that requires encrypting information before sending it over. I have got 64 character long string to use it as a key.
    I am getting ORA-06502: PL/SQL: numeric or value error: raw variable length too long
    <pre>
    declare
    input_string VARCHAR2 (200) := 'SomeText';
    output_string VARCHAR2 (200);
    encrypted_raw RAW (2000); -- stores encrypted binary text
    decrypted_raw RAW (2000); -- stores decrypted binary text
    key_bytes_raw RAW (32); -- stores 256-bit encryption key
    encryption_type PLS_INTEGER; -- total encryption type
    begin
    DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
    encryption_type := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
    key_bytes_raw := UTL_I18N.STRING_TO_RAW('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6', 'AL32UTF8');
    encrypted_raw := DBMS_CRYPTO.ENCRYPT
    src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
    typ => encryption_type,
    key => key_bytes_raw
    -- The encrypted value in the encrypted_raw variable can be used here
    decrypted_raw := DBMS_CRYPTO.DECRYPT
    src => encrypted_raw,
    typ => encryption_type,
    key => key_bytes_raw
    output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
    DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    Please let me know hot to convert 64 character long string in to 256bit key.
    Thanks
    -Smith

    smith_apex wrote:
    My client is using Java and they are saying that they are using this key for their AES256 Encryption and working fine. I have asked them to provide me 32 bytes key as in Oracle 256bit is 32 character string.
    Let me see what they have to say.
    I was wondering why Java has 64 bytes for 256 AES encryption when Oracle need only 32 bytes for same encryption.I am not sure I completely understand how those built-in packages work but the doc example produces the raw key that is same in length (in terms of number of characters) as the one you are using.
    Yet your UTL_I18N packaged function fails for your key but works for the documentation example.
    Documentation example:
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Release 10.2.0.5.0 - Production
    PL/SQL Release 10.2.0.5.0 - Production
    CORE     10.2.0.5.0     Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    declare
       input_string       VARCHAR2 (200) := 'Secret Message';
       output_string      VARCHAR2 (200);
       encrypted_raw      RAW (2000);             -- stores encrypted binary text
       decrypted_raw      RAW (2000);             -- stores decrypted binary text
       num_key_bytes      NUMBER := 256/8;        -- key length 256 bits (32 bytes)
       key_bytes_raw      RAW (32);               -- stores 256-bit encryption key
       encryption_type    PLS_INTEGER :=          -- total encryption type
                                DBMS_CRYPTO.ENCRYPT_AES256
                              + DBMS_CRYPTO.CHAIN_CBC
                              + DBMS_CRYPTO.PAD_PKCS5;
    begin
       DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
       DBMS_OUTPUT.PUT_LINE ('Encryption Type: ' || encryption_type);
       key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES (num_key_bytes);
       DBMS_OUTPUT.PUT_LINE ('Key Bytes(RAW): ' || key_bytes_raw);
       encrypted_raw := DBMS_CRYPTO.ENCRYPT
             src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
             typ => encryption_type,
             key => key_bytes_raw
       DBMS_OUTPUT.PUT_LINE ('Encrypted string: ' || encrypted_raw);
        -- The encrypted value in the encrypted_raw variable can be used here
       decrypted_raw := DBMS_CRYPTO.DECRYPT
             src => encrypted_raw,
             typ => encryption_type,
             key => key_bytes_raw
       output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    32   33   34  /
    Original string: Secret Message
    Encryption Type: 4360
    Key Bytes(RAW): 52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF
    Encrypted string: 0BDDC2B94F7044700D85624297A39025
    Decrypted string: Secret Message
    PL/SQL procedure successfully completed.
    SQL> select length('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF') from dual ;
    LENGTH('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF')
                                                 64
    SQL> select dump('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF') from dual ;
    DUMP('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF')
    Typ=96 Len=64: 53,50,69,67,54,54,53,48,56,70,68,70,49,69,53,68,69,53,70,68,51,56,69,67,50,52,54,55,70,65,65,57,49,48,48,57,66,55,51,56,65,50,57,50,54,65,65,56,55,48,69,49,
    52,50,67,48,56,48,67,55,50,69,66,70Your example:
    declare
       input_string       VARCHAR2 (200) := 'SomeText';
       output_string      VARCHAR2 (200);
       encrypted_raw      RAW (2000);             -- stores encrypted binary text
       decrypted_raw      RAW (2000);             -- stores decrypted binary text
       key_bytes_raw      RAW (32);               -- stores 256-bit encryption key
       encryption_type    PLS_INTEGER;          -- total encryption type
    begin
       DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
       encryption_type :=   DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
       key_bytes_raw := UTL_I18N.STRING_TO_RAW('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6', 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Key Bytes(RAW): ' || key_bytes_raw);
       encrypted_raw := DBMS_CRYPTO.ENCRYPT
             src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
             typ => encryption_type,
             key => key_bytes_raw
        -- The encrypted value in the encrypted_raw variable can be used here
       decrypted_raw := DBMS_CRYPTO.DECRYPT
             src => encrypted_raw,
             typ => encryption_type,
             key => key_bytes_raw
       output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    27   28   29   30  /
    Original string: SomeText
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: raw variable length too long
    ORA-06512: at line 12
    SQL> select length('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6') from dual ;
    LENGTH('EICCMKJD94JFGNIW03LJKDLFUTCNV3209KFJD67023JLCLMXZLMC9543YKFLSEU6')
                                                 64
    SQL> select dump('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6') from dual ;
    DUMP('EICCMKJD94JFGNIW03LJKDLFUTCNV3209KFJD67023JLCLMXZLMC9543YKFLSEU6')
    Typ=96 Len=64: 101,105,99,99,109,107,106,100,57,52,106,102,103,110,105,119,48,51,108,106,107,100,108,102,117,116,99,110,118,51,50,48,57,107,102,106,100,54,55,48,50,51,106,
    108,99,108,109,120,122,108,109,99,57,53,52,51,121,107,102,108,115,101,117,54

Maybe you are looking for

  • In Firefox, I keep getting "Server not found" error - CONSTANTLY!

    Two days ago I started getting the "server not found" error, off and on, daily. It is happening on both my desktop iMac 10.7, and my Windows 7 laptop. I keep having to hit the "Try Again" butting, and sometimes, several times, before a web site will

  • Voice mail and online number

    I have set up voice mail for my account; then bought an online number. When I called my online number from my iPhone, it did not answer with voice mail. Do I have to set up a NEW voice mail for my new online number? 

  • Inventory Report with Trading Partners & Cost of Sales

    Hi Freinds, We have activated the Trading Partners in the document types relating to the Invoice Verification and Goods Receipts. Accordingly when we do the GR or the Invoice Verification, the Trading Partner information gets picked up at the time of

  • How do I re-size a photo

    I've used Photoshop for years but Lightroom is very much harder to use.  All I want to do is re-size a photo to put on the web, print a particular size, etc.  This should be easy but I give up.

  • How can I import an excel sheet and have it be functional in iOS Numbers?

    Pretty much exactly as title.  To summarize, I'm a kinesiologist and I've developed a pretty complex spreadsheet that enables me to program exercise prescriptions on the fly but I want to be able to take it with me more portably on my ipad air.  Unfo