String replace (first occurence)

Hi:
I have a input file that contains the following -
set var=
set var=%2
Now, I need to replace the first occurence of set var= with set var=value, so ouptut file should look like
set var=value
set var=%2
Apparently my code seems to change all occurences of set var= inspite of using replaceFirst, can you please point out what I am missing?
while((varLine = InputFile.readLine()) != null)
                 if(varLine.endsWith("="))
              new_varLine = varLine.replaceFirst(find_string,replacement_string);
             OutputFile.write(var_envLine);
                 OutputFile.write("\n");
            }

uncle_alice wrote:
Just set a flag when you've done the replacement: boolean didIt = false;Or a sequential program, which can be clearer than adding conditional logic in loops.
while((varLine = inputFile.readLine()) != null && ! varLine.matches("\\s*set\\s+var\\s*=\\s*"))  {
   outputFile.write(varLine);
   outputFile.write("\n");
if (varLine == null) return;
outputFile.write(varLine + replacement_string);
outputFile.write("\n");
while((varLine = inputFile.readLine()) != null) {
   outputFile.write(varLine);
   outputFile.write("\n");
{code}
IME in debugging more complicated code the less state you have to think about when working out what the computer should be doing at any part of the code, the better. Most flags can be converted to breaks, continues or method calls; finally lets you clean up on early returns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Replace all occurences in 4.6c

    Hi,
    I have a program which analyse system and gives some output.(Regarding programs,FM's etc).
    I need to run this my present server which is of 4.6c.
    But this program developed in ECC 6.0 and when i loaded this notepad program it was giving some errors.
    One error is REPLACE all occurrences of '('  in i_userexit-txt WITH space.
    In 4.6 c it is not accepting ALL OCCURENCES.
    It is accepting only Replace first occurence.
    What i need to do to replace all occurences in 4.6C?
    I there any statement to replace all Occurences?
    I searched in ABAP help  for 4.6c also.
    Please help to correct this.
    Regards,
    Krishna.

    you can do something like this, this wil do REPLACE ALL OCC...:
    WHILE sy-subrc EQ 0.
    REPLACE ... " acc. to 4.6 Syntax ...
    ENDWHILE.

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

  • What is the unicode for ''  (need it to do String.replace)

    i'm trying to use String.replace(char a, char b)
    it won't compile if i do x.replace('_', '')
    help!
    thanks!

    Are you trying to remove all occurences of the underscore character from the string? If so create a StringBuffer from the string, loop through it and remove the characters as you find them.
    If you're using JDK1.4 you should eb able to use the new String method:
    public String replaceAll(String regex,
    String replacement)

  • [AS CS3] Search first occurence then next search item

    Hi!
    I have a 1000+ page book. I need to change several (2000+) names to character style but only first occurence of that name and then search first occurence of next name. Names are on a text file which i read to AS but if i use
    set myFoundItems to change text
    it searches all occurences of find text and changes to character style.
    What i need is a script that searches first occurence of name "AAA", changes that to character style "Whatever" and then proceeds to search name "BBB" and changes that too. Only first occurences of search.
    It would be wery handy if the second search (BBB) would start right after the "AAA" and not from the beginning of teh story.
    Any ideas?
    Thanks

    On 19/2/08 9:39 PM, "Jukka Lauhalahti" <[email protected]> wrote:<br /><br />> if one could just exit the seach/replace loop after found one item and search<br />> next item in the list from that position would speed the script...<br /><br />It would, but you can't...<br /><br /><br />-- <br />Shane Stanley <[email protected]>

  • String Replace  has $

    Hi All,
    How do i replace the text with text that has $.
    String s = "Sample text XYZ";
    s.replaceAll(XYZ, "$ABC");
    Error: Illegal Group Reference.
    "\\$ABC" works.
    In my case "$ABC" is dynamic text. Position of $ can be any where in in the text, need not be first char.
    TIA,
    Kishore.

    I think you'd need to find the $ in your search string first and put the escape character in their before attempting to do the replace all. In case you're unaware, RegEx uses $ as a special character, so that's why it must be replaced..
    String a = "This is XYZ";
    String replace = "$ABC";
    StringBuffer sb = new StringBuffer(replace);
    sb.insert(sb.indexOf("$"), "\\ ");
    a = a.replaceAll("XYZ", sb.toString());
    System.out.println(a);(Note: The extra space after the \\ in the insert was just so this forum would display everything properly).

  • PHP String Replace

    I am looking to add my date to the beginning of my articles.
    Previously, I
    was using the string replace function to look for the
    begininng of my
    paragraph and then place the date in front of that. Bad Jon!
    I forgot that
    any article with multiple paragraphs would then have multiple
    dates.
    $artContent = str_replace('<p>', '<p>
    '.$artDateEdited.' - ',
    $artContent);
    So, what I am looking for is how do I do a string replaceon
    just the first
    paragraph?
    TIA,
    Jon Parkhurst
    PriivaWeb
    http://priiva.net.

    Are you sure there are <p> tags in the data? The only
    way that could get
    there would be if someone explicitly put them there.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "crash" <[email protected]> wrote in message
    news:[email protected]...
    > LOL, just now getting back to this.
    >
    > I've got myself in a little bit of a bind, b/c I didn't
    foresee my data
    > having more than one paragraph.
    >
    > This is what I'm thinking of doing. If there's a better
    way, can somebody
    > pipe in?
    >
    > Take data from database.
    > Search for <p> tags, and capture all text within
    the first instances
    > Limit text to X number of chars
    > Replace <p> tags, and my ...Full Story links
    >
    > Looking now through all of the string functions and
    preg_replace right
    > now.
    >
    > Basically, I"m having some problems finding a function
    that will replace
    > $var on the Xth instance.
    >
    > Will post tomorrow with my results.
    > "Joe Makowiec" <[email protected]> wrote in
    message
    >
    news:[email protected]...
    >> On 26 Aug 2006 in macromedia.dreamweaver.appdev,
    crash wrote:
    >>
    >>> I am looking to add my date to the beginning of
    my articles.
    >>> Previously, I was using the string replace
    function to look for the
    >>> begininng of my paragraph and then place the
    date in front of that.
    >>> Bad Jon! I forgot that any article with multiple
    paragraphs would
    >>> then have multiple dates.
    >>>
    >>> $artContent = str_replace('<p>',
    '<p>
    >>> '.$artDateEdited.' - ',
    >>> $artContent);
    >>>
    >>> So, what I am looking for is how do I do a
    string replaceon just the
    >>> first paragraph?
    >>
    >>
    http://www.php.net/manual/en/function.preg-replace.php
    >>
    >> In particular, the optional 4th parameter to
    preg_replace() is a limit;
    >> you can set this to 1.
    >>
    >> --
    >> Joe Makowiec
    >>
    http://makowiec.net/
    >> Email:
    http://makowiec.net/email.php
    >
    >

  • SSMS 2012:XQuery-doing "Retriving Job Candidates with the query Method" in AdventuresWorks 2012. Unclosed quotation mark after string '//*:Name.First?

    Hi all,
    From Page 354 of the the Book "Pro T-SQL 2008 Programmer's Guide" written by Michael Coles (published by apress), I copied the following code (Listing 12-9 Retrieving Job Candidates with the query Method):
    --Coles12_9.sql // saved in C:/Documemnts/SQL Server Management Studio
    -- Coles Listing 12-9 Retrieving Job Candidates with the query Method
    -- Doing XQuery and the xml Data Type in AdvantureWorks
    -- 17 March 2015 1105 AM
    USE AdventureWorks;
    GO
    SELECT Resume.query
    N'//*:Name.First,
    //*:Name.Middle,
    //*:Name.Last,
    //*:Edu.Level
    FROM HumanResources.JobCandidate;
    I executed this set of Listing 12-9 code in my SQL Server 2012 Management Studio and I got the following error messages:
    Msg 105, Level 15, State 1, Line 4
    Unclosed quotation mark after the character string '//*:Name.First,
    //*:Name.Middle,
    //*:Name.Last,
    //*:Edu.Level
    FROM HumanResources.JobCandidate;
    Msg 102, Level 15, State 1, Line 4
    Incorrect syntax near '//*:Name.First,
    //*:Name.Middle,
    //*:Name.Last,
    //*:Edu.Level
    FROM HumanResources.JobCandidate;
    I am not able to figure out why I got the error messages.  Please kindly help and advise me how to correct this set of sql codes.
    Thanks in advance,
    Scott Chang

    Hi Scott,
    I don't have that book at hand, but your problem is the "Unclosed quotationmark after the character string",as the error message shows. You have to enclose the 'XQUERY' string quotation in the
    query().
    SELECT jobcandidateid, Resume.query
    N'//*:resume,
    //*:Name.Middle,
    //*:Name.Last,
    //*:Edu.Level' --enclose the quotation here
    FROM HumanResources.JobCandidate;
    For XQUERY learning, here is a good
    link.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • First occurence of a value from a  field in the internal table.

    How to select the first occurence of a value from a field in an internal table ?
    I don think , we can use select query .
    Any suggestions?
    provide syntaxs also .

    Hi...
    You have to use this code.
    DATA : Begin of IT_MARA occurs 0,
                 mtart type mara-mtart,
                 matnr type mara-matnr,
                 meins type mara-meins,
              END OF IT_MARA.
    START-of-SELECTION.
      SELECT MTART MATNR MEINS FROM MARA INTO TABLE IT_MARA.
    END-OF-SELECTION.
    LOOP AT  IT_MARA.
    <b>  AT NEW MTART.      "This will trigger for every first/new value of the field
                 <<<<WRITE YOUR CODE here>>
       ENDAT.</b>
    ENDLOOP.
    You can also use.
    LOOP AT  IT_MARA.
    <b> <b>  ON CHANGE OF IT_MARA-TART.   
                 <<<<WRITE YOUR CODE here>>
       ENDON.</b></b>
    ENDLOOP.
    <b>Reward if Helpful.</b>

  • String replacement

    Hi, anyone knows how to replace a particular string in a file with another string?
    For example, in the file hello.tmp,
    I want to replace the word :Smile: with the string
    <img src="smile.gif">
    I tried to use String.replace() but this is only for characters.
    Anyone knows how to replace Strings??
    Hope to hear from anyone really soon. Very urgent!!!

    There is no direct method to replace a string in file. The code goes like this:
    import java.io.*;
    import java.util.*;
    public class StringReplacer
         private String replaceString;
         private String replacerString;
         private String filePath;
         public StringReplacer(String replaceString, String replacerString, String filePath)
              this.replaceString = replaceString;
              this.replacerString = replacerString;
              this.filePath = filePath;
              try
                   replace();               
              catch (Exception ex)
         private void replace() throws Exception
              File file = new File(filePath);
              if(!file.exists())
                   System.out.println("File doesnot exists");
                   return;
              DataInputStream dis = new DataInputStream(new FileInputStream(file));
              StringBuffer fileData = new StringBuffer("");
              String strTemp = "";
              while((strTemp = dis.readLine()) != null)
                   fileData.append(strTemp);
              dis.close();
              StringTokenizer stTemp = new StringTokenizer(fileData.toString(), replaceString);
              int tokens = stTemp.countTokens();
              if(tokens <= 1)
                   //No matches found for string to be replaces.
                   System.out.println("No matches found for string to be replaced");
                   return;
              fileData = new StringBuffer("");
              while(stTemp.hasMoreTokens())
                   fileData.append(stTemp.nextToken() + replacerString);     
              if(file.exists())
                   file.delete();
              file = new File(filePath);
              if(!file.exists())
                   file.createNewFile();
              DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
              dos.writeChars(fileData.toString());
              dos.flush();
              dos.close();
         public static void main(String [] args)
              //create an object of StringReplacer here.
    }

  • String replace

    String has a replace method for chars, something the likes of
    String replace(char a, char b)
    I tend to think it would be nice to ammend String further with
    String replace(String a, String b)
    proponents/opponents? It seems like a nice thing to have.

    This type of method is available in the regex package
    (available in JDK 1.4). I am not expert or regular
    expressions but it will allow you to do this and much
    much more.I guess it will. Still it would be nice to have the ability directly inside String without explicitly having to instantiate a Pattern. I know there is a split method in String in JSDK 1.4 which takes a String specification of a regexp and internally compiles it. I guess my point is convenience but I should know the new APIs fully before writing more.

  • 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, '~', '&');

  • Regarding String Replacing ....

    Hi Friends,
    I have some problem regarding String replacing.
    ex.
    I have following string ::
    =================================================
    This is the java manager the main purpose for the jasper is used to create reports.
    And the Java language is very extensible.
    Is this the proper string functions provided by java isn't it ?
    *================================================*
    *i want to replace word "is"  with "IS". but that word is not connected to word like  Th{color:#ff00ff}is{color}*
    *differ from simple separate "{color:#ff0000}is{color}" so Word should not be replaced in This only separate "is"*
    *must be replaced. ?*
    *Any Idea ?*
    *{color}*
    Edited by: Ghanshyam on Sep 14, 2007 4:27 PM

    How about just searching for and replacing
    " is "
    instead of
    "is"
    So, using this code from the Java Developers Almanac 1.4 (2002 Addison-Wesley):-
    static String replace(String str, String pattern, String replace) {>    int s = 0;>    int e = 0;>    StringBuffer result = new StringBuffer();> >    while ((e = str.indexOf(pattern, s)) >= 0) {>       result.append(str.substring(s, e));>       result.append(replace);>       s = e+pattern.length();>  result.append(str.substring(s));
    return result.toString();
    }Your would use:-
    String newStr = replace(originalStr, " is "," IS ");
    Edited by: mad_scientist on Sep 14, 2007 4:16 AM (Sorry about all the edits, just getting used to the formatting on here)
    Edited by: mad_scientist on Sep 14, 2007 4:22 AM
    Edited by: mad_scientist on Sep 14, 2007 4:24 AM

  • PLD String Replace Function?

    Hello Experts,
    I would like to use the Sum in Words option in the field properties Format tab. However, I would like to have this in a language for which there is no LRF.
    I have read all the various Sum in Words/Amount in Words threads I can find but I have no special locale based requirements (lacs etc). The default answer seems to be to prepare a FMS query and attach it to a UDF, then pull the variable into PLD.
    Rather than rewriting the functionality, it would be far easier for me to use a series of Replace functions (the structure of Turkish for amount in words is exactly the same as English and translating each word (One, Two... Ten, Twenty... etc) with a Replace would solve my problem.
    Looking at the documentation for PLD, I can see no prebuilt Replace function - is there any way this can be achieved?
    If not, is there any Sum in Words function in B1 queries so I can at least do the replace there rather than writing an entire convert to words query?
    Thank you.

    Wasn't able to force a string replace - had to hex edit the LRF instead. Quick and dirty, but it works.

  • Highlight Words - only the first occurence

    Hi,
    I'm using the "Highlight Words" column formating for a report. There, I'm using the item syntax: &P1_RENVOI. Problem is, when the report appear, only the first occurence of the value of item "P1_RENVOI" is in red for every field in that column.
    Is this a normal feature or should all occurences be put in red?
    Thanks in advance.
    ApEx version: 4.2.1.00.08.
    Theme: Business - 3

    Hi,
    I'm using the "Highlight Words" column formating for a report. There, I'm using the item syntax: &P1_RENVOI. Problem is, when the report appear, only the first occurence of the value of item "P1_RENVOI" is in red for every field in that column.
    Is this a normal feature or should all occurences be put in red?
    Thanks in advance.
    ApEx version: 4.2.1.00.08.
    Theme: Business - 3

Maybe you are looking for

  • Change font in a live font

    So I am using the Burn Barrel live font in Motion but I do not like the plain font that is used. I want to use another font on my system. How do I make it so that the font I choose is the one burning instead of the default one that Motion makes me us

  • Automation in Crystal Report XI

    Post Author: jchan CA Forum: General Hi all, I am really new to crystal report XI; hopefully someone can point me in the right direction; I currently have 8 report written in crystal report that i have run weekly; i was wonder is there anyway i can a

  • About changing the ipod's video settings????

    danielc2 Posts: 12 From: Massachusetts Registered: Mar 9, 2006 Re: Also can't get video on my tv Posted: Mar 20, 2006 2:16 PM in response to: sassay Also, make sure the Video Output setting on your ipod is set to NTSC instead of PAL. Ok I understand

  • How to replace the virtual system as the real system in the TMS?

    Hi, I have a standard 3 systems TMS, which is 1 development system (real system, transport domain) and 2 virtual system(QAS and PRD). And now, I will install the QAS system and replace the virtual system as the real one, How can I do in TMS? I should

  • DML Debugging is a nightmare!

    It's not the first time I change some items and suddenly the Automatic DML process raises an Oracle error I could not understand. The debug function cannot help me. Why doesn't show it the generated SQL? It would make debugging so much easier! Now I