How to replace numbers in a string?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I have a long string list:



string = "E:\job\a\000251.png", "E:\job\a\000252.png",
"E:\job\a\000253.png", "E:\job\a\000254.png",
"E:\job\a\000255.png", "E:\job\a\000256.png"


Now, I want to add 2 to the file name base when the file base name is an even number. I mean, I hope to get such new string list:



string = "E:\job\a\000251.png", "E:\job\a\000254.png",
"E:\job\a\000253.png", "E:\job\a\000256.png",
"E:\job\a\000255.png", "E:\job\a\000258.png"


How to implement it?










share|improve this question



























    up vote
    5
    down vote

    favorite
    1












    I have a long string list:



    string = "E:\job\a\000251.png", "E:\job\a\000252.png",
    "E:\job\a\000253.png", "E:\job\a\000254.png",
    "E:\job\a\000255.png", "E:\job\a\000256.png"


    Now, I want to add 2 to the file name base when the file base name is an even number. I mean, I hope to get such new string list:



    string = "E:\job\a\000251.png", "E:\job\a\000254.png",
    "E:\job\a\000253.png", "E:\job\a\000256.png",
    "E:\job\a\000255.png", "E:\job\a\000258.png"


    How to implement it?










    share|improve this question

























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I have a long string list:



      string = "E:\job\a\000251.png", "E:\job\a\000252.png",
      "E:\job\a\000253.png", "E:\job\a\000254.png",
      "E:\job\a\000255.png", "E:\job\a\000256.png"


      Now, I want to add 2 to the file name base when the file base name is an even number. I mean, I hope to get such new string list:



      string = "E:\job\a\000251.png", "E:\job\a\000254.png",
      "E:\job\a\000253.png", "E:\job\a\000256.png",
      "E:\job\a\000255.png", "E:\job\a\000258.png"


      How to implement it?










      share|improve this question















      I have a long string list:



      string = "E:\job\a\000251.png", "E:\job\a\000252.png",
      "E:\job\a\000253.png", "E:\job\a\000254.png",
      "E:\job\a\000255.png", "E:\job\a\000256.png"


      Now, I want to add 2 to the file name base when the file base name is an even number. I mean, I hope to get such new string list:



      string = "E:\job\a\000251.png", "E:\job\a\000254.png",
      "E:\job\a\000253.png", "E:\job\a\000256.png",
      "E:\job\a\000255.png", "E:\job\a\000258.png"


      How to implement it?







      string-manipulation stringreplace






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 mins ago









      Johu

      2,776929




      2,776929










      asked 6 hours ago









      yode

      9,79823097




      9,79823097




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote













          You could create a helper function (the point of the helper function is to avoid calling FromDigits twice):



          incString[s_] := With[r = FromDigits[s],
          If[EvenQ[r],
          IntegerString[r+2, 10, StringLength[s]],
          s
          ]
          ]


          and then use this helper function in StringReplace:



          StringReplace[
          string,
          i:DigitCharacter..~~".png" :> incString[i]<>".png"
          ]



          "E:joba00251.png", "E:joba00254.png",
          "E:joba00253.png", "E:joba00256.png", "E:joba00255.png",
          "E:joba00258.png"







          share|improve this answer





























            up vote
            2
            down vote













            StringReplace[string, 
            a : NumberString ~~ "." /; EvenQ[FromDigits[a]] :>
            StringJoin[ToString /@
            PadLeft[IntegerDigits[FromDigits[a] + 2], StringLength@a]] ~~ "."]



            "E:joba00251.png",

            "E:joba00254.png",

            "E:joba00253.png",

            "E:joba00256.png",

            "E:joba00255.png",

            "E:joba00258.png"







            share|improve this answer






















            • Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
              – yode
              5 hours ago










            • see here please.
              – yode
              5 hours ago










            • @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
              – kglr
              5 hours ago

















            up vote
            0
            down vote













            Here is an approach without StringReplace. It is one function f that first destructures the file-name and has two more definitions: one for files with an even number and one for all others.



            ClearAll[f]
            f[str_String] := f[str, DirectoryName[str], FileBaseName[str], FileExtension[str]];

            f[str_, dir_, name_, ext_ /; ToExpression[name, InputForm, EvenQ]] :=
            With[
            num = IntegerString[FromDigits[name] + 2, 10, StringLength[name]]
            , FileNameJoin[dir, num <> "." <> ext]];

            f[str_, __] := str


            Now better test it properly since my last version was completely screwed up. I need to make Linux filenames from your strings since otherwise, Mathematica's file functions don't work here. On your Windows machine, this should not be necessary.



            string = "E:\job\a\000251.png", "E:\job\a\000252.png", 
            "E:\job\a\000253.png", "E:\job\a\000254.png",
            "E:\job\a\000255.png", "E:\job\a\000256.png";
            string = StringReplace[string, "E:\" :> "/", "\" :> "/"]

            f/@string//Column
            (*
            /job/a/000251.png
            /job/a/000254.png
            /job/a/000253.png
            /job/a/000256.png
            /job/a/000255.png
            /job/a/000258.png
            *)





            share|improve this answer






















            • I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
              – Jack LaVigne
              2 hours ago










            • @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
              – halirutan♦
              2 hours ago










            • Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
              – Jack LaVigne
              2 hours ago










            • It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
              – Carl Woll
              2 hours ago










            • @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
              – halirutan♦
              2 hours ago










            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181917%2fhow-to-replace-numbers-in-a-string%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            You could create a helper function (the point of the helper function is to avoid calling FromDigits twice):



            incString[s_] := With[r = FromDigits[s],
            If[EvenQ[r],
            IntegerString[r+2, 10, StringLength[s]],
            s
            ]
            ]


            and then use this helper function in StringReplace:



            StringReplace[
            string,
            i:DigitCharacter..~~".png" :> incString[i]<>".png"
            ]



            "E:joba00251.png", "E:joba00254.png",
            "E:joba00253.png", "E:joba00256.png", "E:joba00255.png",
            "E:joba00258.png"







            share|improve this answer


























              up vote
              3
              down vote













              You could create a helper function (the point of the helper function is to avoid calling FromDigits twice):



              incString[s_] := With[r = FromDigits[s],
              If[EvenQ[r],
              IntegerString[r+2, 10, StringLength[s]],
              s
              ]
              ]


              and then use this helper function in StringReplace:



              StringReplace[
              string,
              i:DigitCharacter..~~".png" :> incString[i]<>".png"
              ]



              "E:joba00251.png", "E:joba00254.png",
              "E:joba00253.png", "E:joba00256.png", "E:joba00255.png",
              "E:joba00258.png"







              share|improve this answer
























                up vote
                3
                down vote










                up vote
                3
                down vote









                You could create a helper function (the point of the helper function is to avoid calling FromDigits twice):



                incString[s_] := With[r = FromDigits[s],
                If[EvenQ[r],
                IntegerString[r+2, 10, StringLength[s]],
                s
                ]
                ]


                and then use this helper function in StringReplace:



                StringReplace[
                string,
                i:DigitCharacter..~~".png" :> incString[i]<>".png"
                ]



                "E:joba00251.png", "E:joba00254.png",
                "E:joba00253.png", "E:joba00256.png", "E:joba00255.png",
                "E:joba00258.png"







                share|improve this answer














                You could create a helper function (the point of the helper function is to avoid calling FromDigits twice):



                incString[s_] := With[r = FromDigits[s],
                If[EvenQ[r],
                IntegerString[r+2, 10, StringLength[s]],
                s
                ]
                ]


                and then use this helper function in StringReplace:



                StringReplace[
                string,
                i:DigitCharacter..~~".png" :> incString[i]<>".png"
                ]



                "E:joba00251.png", "E:joba00254.png",
                "E:joba00253.png", "E:joba00256.png", "E:joba00255.png",
                "E:joba00258.png"








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 4 hours ago

























                answered 5 hours ago









                Carl Woll

                56.8k272147




                56.8k272147




















                    up vote
                    2
                    down vote













                    StringReplace[string, 
                    a : NumberString ~~ "." /; EvenQ[FromDigits[a]] :>
                    StringJoin[ToString /@
                    PadLeft[IntegerDigits[FromDigits[a] + 2], StringLength@a]] ~~ "."]



                    "E:joba00251.png",

                    "E:joba00254.png",

                    "E:joba00253.png",

                    "E:joba00256.png",

                    "E:joba00255.png",

                    "E:joba00258.png"







                    share|improve this answer






















                    • Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                      – yode
                      5 hours ago










                    • see here please.
                      – yode
                      5 hours ago










                    • @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                      – kglr
                      5 hours ago














                    up vote
                    2
                    down vote













                    StringReplace[string, 
                    a : NumberString ~~ "." /; EvenQ[FromDigits[a]] :>
                    StringJoin[ToString /@
                    PadLeft[IntegerDigits[FromDigits[a] + 2], StringLength@a]] ~~ "."]



                    "E:joba00251.png",

                    "E:joba00254.png",

                    "E:joba00253.png",

                    "E:joba00256.png",

                    "E:joba00255.png",

                    "E:joba00258.png"







                    share|improve this answer






















                    • Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                      – yode
                      5 hours ago










                    • see here please.
                      – yode
                      5 hours ago










                    • @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                      – kglr
                      5 hours ago












                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    StringReplace[string, 
                    a : NumberString ~~ "." /; EvenQ[FromDigits[a]] :>
                    StringJoin[ToString /@
                    PadLeft[IntegerDigits[FromDigits[a] + 2], StringLength@a]] ~~ "."]



                    "E:joba00251.png",

                    "E:joba00254.png",

                    "E:joba00253.png",

                    "E:joba00256.png",

                    "E:joba00255.png",

                    "E:joba00258.png"







                    share|improve this answer














                    StringReplace[string, 
                    a : NumberString ~~ "." /; EvenQ[FromDigits[a]] :>
                    StringJoin[ToString /@
                    PadLeft[IntegerDigits[FromDigits[a] + 2], StringLength@a]] ~~ "."]



                    "E:joba00251.png",

                    "E:joba00254.png",

                    "E:joba00253.png",

                    "E:joba00256.png",

                    "E:joba00255.png",

                    "E:joba00258.png"








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 5 hours ago

























                    answered 5 hours ago









                    kglr

                    160k8184384




                    160k8184384











                    • Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                      – yode
                      5 hours ago










                    • see here please.
                      – yode
                      5 hours ago










                    • @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                      – kglr
                      5 hours ago
















                    • Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                      – yode
                      5 hours ago










                    • see here please.
                      – yode
                      5 hours ago










                    • @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                      – kglr
                      5 hours ago















                    Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                    – yode
                    5 hours ago




                    Maybe more concise StringReplace[string, a : DigitCharacter ~~ "." /; EvenQ[FromDigits[a]] :> StringJoin[ToString[FromDigits[a] + 2]] ~~ "."]
                    – yode
                    5 hours ago












                    see here please.
                    – yode
                    5 hours ago




                    see here please.
                    – yode
                    5 hours ago












                    @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                    – kglr
                    5 hours ago




                    @yode, if you don't have elements like "E:joba00258.png" in your string list your more concise version would work too.
                    – kglr
                    5 hours ago










                    up vote
                    0
                    down vote













                    Here is an approach without StringReplace. It is one function f that first destructures the file-name and has two more definitions: one for files with an even number and one for all others.



                    ClearAll[f]
                    f[str_String] := f[str, DirectoryName[str], FileBaseName[str], FileExtension[str]];

                    f[str_, dir_, name_, ext_ /; ToExpression[name, InputForm, EvenQ]] :=
                    With[
                    num = IntegerString[FromDigits[name] + 2, 10, StringLength[name]]
                    , FileNameJoin[dir, num <> "." <> ext]];

                    f[str_, __] := str


                    Now better test it properly since my last version was completely screwed up. I need to make Linux filenames from your strings since otherwise, Mathematica's file functions don't work here. On your Windows machine, this should not be necessary.



                    string = "E:\job\a\000251.png", "E:\job\a\000252.png", 
                    "E:\job\a\000253.png", "E:\job\a\000254.png",
                    "E:\job\a\000255.png", "E:\job\a\000256.png";
                    string = StringReplace[string, "E:\" :> "/", "\" :> "/"]

                    f/@string//Column
                    (*
                    /job/a/000251.png
                    /job/a/000254.png
                    /job/a/000253.png
                    /job/a/000256.png
                    /job/a/000255.png
                    /job/a/000258.png
                    *)





                    share|improve this answer






















                    • I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                      – Jack LaVigne
                      2 hours ago










                    • @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                      – halirutan♦
                      2 hours ago










                    • Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                      – Jack LaVigne
                      2 hours ago










                    • It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                      – Carl Woll
                      2 hours ago










                    • @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                      – halirutan♦
                      2 hours ago














                    up vote
                    0
                    down vote













                    Here is an approach without StringReplace. It is one function f that first destructures the file-name and has two more definitions: one for files with an even number and one for all others.



                    ClearAll[f]
                    f[str_String] := f[str, DirectoryName[str], FileBaseName[str], FileExtension[str]];

                    f[str_, dir_, name_, ext_ /; ToExpression[name, InputForm, EvenQ]] :=
                    With[
                    num = IntegerString[FromDigits[name] + 2, 10, StringLength[name]]
                    , FileNameJoin[dir, num <> "." <> ext]];

                    f[str_, __] := str


                    Now better test it properly since my last version was completely screwed up. I need to make Linux filenames from your strings since otherwise, Mathematica's file functions don't work here. On your Windows machine, this should not be necessary.



                    string = "E:\job\a\000251.png", "E:\job\a\000252.png", 
                    "E:\job\a\000253.png", "E:\job\a\000254.png",
                    "E:\job\a\000255.png", "E:\job\a\000256.png";
                    string = StringReplace[string, "E:\" :> "/", "\" :> "/"]

                    f/@string//Column
                    (*
                    /job/a/000251.png
                    /job/a/000254.png
                    /job/a/000253.png
                    /job/a/000256.png
                    /job/a/000255.png
                    /job/a/000258.png
                    *)





                    share|improve this answer






















                    • I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                      – Jack LaVigne
                      2 hours ago










                    • @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                      – halirutan♦
                      2 hours ago










                    • Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                      – Jack LaVigne
                      2 hours ago










                    • It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                      – Carl Woll
                      2 hours ago










                    • @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                      – halirutan♦
                      2 hours ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Here is an approach without StringReplace. It is one function f that first destructures the file-name and has two more definitions: one for files with an even number and one for all others.



                    ClearAll[f]
                    f[str_String] := f[str, DirectoryName[str], FileBaseName[str], FileExtension[str]];

                    f[str_, dir_, name_, ext_ /; ToExpression[name, InputForm, EvenQ]] :=
                    With[
                    num = IntegerString[FromDigits[name] + 2, 10, StringLength[name]]
                    , FileNameJoin[dir, num <> "." <> ext]];

                    f[str_, __] := str


                    Now better test it properly since my last version was completely screwed up. I need to make Linux filenames from your strings since otherwise, Mathematica's file functions don't work here. On your Windows machine, this should not be necessary.



                    string = "E:\job\a\000251.png", "E:\job\a\000252.png", 
                    "E:\job\a\000253.png", "E:\job\a\000254.png",
                    "E:\job\a\000255.png", "E:\job\a\000256.png";
                    string = StringReplace[string, "E:\" :> "/", "\" :> "/"]

                    f/@string//Column
                    (*
                    /job/a/000251.png
                    /job/a/000254.png
                    /job/a/000253.png
                    /job/a/000256.png
                    /job/a/000255.png
                    /job/a/000258.png
                    *)





                    share|improve this answer














                    Here is an approach without StringReplace. It is one function f that first destructures the file-name and has two more definitions: one for files with an even number and one for all others.



                    ClearAll[f]
                    f[str_String] := f[str, DirectoryName[str], FileBaseName[str], FileExtension[str]];

                    f[str_, dir_, name_, ext_ /; ToExpression[name, InputForm, EvenQ]] :=
                    With[
                    num = IntegerString[FromDigits[name] + 2, 10, StringLength[name]]
                    , FileNameJoin[dir, num <> "." <> ext]];

                    f[str_, __] := str


                    Now better test it properly since my last version was completely screwed up. I need to make Linux filenames from your strings since otherwise, Mathematica's file functions don't work here. On your Windows machine, this should not be necessary.



                    string = "E:\job\a\000251.png", "E:\job\a\000252.png", 
                    "E:\job\a\000253.png", "E:\job\a\000254.png",
                    "E:\job\a\000255.png", "E:\job\a\000256.png";
                    string = StringReplace[string, "E:\" :> "/", "\" :> "/"]

                    f/@string//Column
                    (*
                    /job/a/000251.png
                    /job/a/000254.png
                    /job/a/000253.png
                    /job/a/000256.png
                    /job/a/000255.png
                    /job/a/000258.png
                    *)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 hours ago

























                    answered 4 hours ago









                    halirutan♦

                    92.8k5212405




                    92.8k5212405











                    • I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                      – Jack LaVigne
                      2 hours ago










                    • @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                      – halirutan♦
                      2 hours ago










                    • Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                      – Jack LaVigne
                      2 hours ago










                    • It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                      – Carl Woll
                      2 hours ago










                    • @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                      – halirutan♦
                      2 hours ago
















                    • I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                      – Jack LaVigne
                      2 hours ago










                    • @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                      – halirutan♦
                      2 hours ago










                    • Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                      – Jack LaVigne
                      2 hours ago










                    • It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                      – Carl Woll
                      2 hours ago










                    • @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                      – halirutan♦
                      2 hours ago















                    I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                    – Jack LaVigne
                    2 hours ago




                    I have the greatest admiration for your contributions. I am trying to follow your answer but I believe there is an error in the second definition of f. num is defined as a local constant in With but never used in the output. I would also appreciate it if you would show how to use f for the given example.
                    – Jack LaVigne
                    2 hours ago












                    @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                    – halirutan♦
                    2 hours ago




                    @JackLaVigne Oh my goodness. There was so much wrong in my code because I didn't clear f for testing. Thank you for paying attention! Would you test if it works on windows with the original definition of strings?
                    – halirutan♦
                    2 hours ago












                    Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                    – Jack LaVigne
                    2 hours ago




                    Works fine in Windows. I was thinking I had to Map the function f`` over string`. Thank you for the update and example. It is clear to me now.
                    – Jack LaVigne
                    2 hours ago












                    It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                    – Carl Woll
                    2 hours ago




                    It doesn't work for "/job/a/000258.png" where f returns "/job/a/0002510.png".
                    – Carl Woll
                    2 hours ago












                    @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                    – halirutan♦
                    2 hours ago




                    @CarlWoll If you are on Windows, then this seems to be expected. Filename separators are OS specific and Mathematica's functions don't work if you are on Windows and try Unix files.
                    – halirutan♦
                    2 hours ago

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181917%2fhow-to-replace-numbers-in-a-string%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke