Help with search and replace

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I'm trying to do a simple search and replace with some unkowns.

    So I got strings like this:

    • <property name="Map ID" type="int" value="103"/>
    • <property name="Map ID" type="int" value="2"/>
    • etc.

    Notice that last value is always changing.
    Now I want to do an operation that changes that last value. Is there some text expression I can use here to find the value in the string and replace it with something else?

    I tried looking into "wildcards", but no luck.

  • To find the values you may use the String Parser object.

    Thanks, how would you use the String parser for this?

    Also, the strings I want to edit is a part of a larger XML, where I just want to change that single line with the "Map ID" value.
    I am attaching a file which shows the XML file I am working with. I've manage to select parts of the relevant line I want to change. If I somehow could manage to select the entire line, I cold easily replace it.

  • Fusion's native string expressions probably give you all you need for this:


    Please login to see this picture.

    It's all pretty logical, but you have to break down the process step by step, which can get quite tedious.


    For example, if you want to learn what the Map ID is, you'd probably use the extract middle substring expression to find it. When you select it, it will look like this:

    Code
    Mid$(>Enter string<, >Enter first character number<, >Enter number of characters<)


    The first parameter is the string you're searching: <property name="Map ID" type="int" value="103"/>. If entering it manually, remember to use double quotation marks "" to allow the quotation marks to be part of the string. So the first parameter would be "<property name=""Map ID"" type=""int"" value=""103""/>"

    For the second parameter, you might use the Find expression to search for "value=""", which would give you the exact character number (as a value) where value="103.... is found. If you added 8 to that, you would have the exact location of where 103"/> starts.

    For the third parameter, you could use the Length of String expression to find the total length of the string, then subtract 45 from it, which should give you the number of digits of your number (3, in the case of 103).


    You would then use the replace substring in a string expression, using similar principles as above, to replace the number in your string.


    The above all relates to searching and modifying a single line string, as in your first post. To search through an entire file, you could use much the same techniques and expressions as above, but first load the entire file into a single string, which you can do using String Parser 2.

    If there's a chance that your desired line would sometimes contain extra spaces here or there, then you might want to use the replace substring in a string expression to first trim out all spaces from your string before you perform any of the operations above, to ensure accurate results.



    Having said all that, I notice that there's an extension called XML parser object that says its supports wildcard searching. You might want to try that first.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Thanks for a detailed answer. I guess my first issue is to successfully select the full line of text.
    Since I want to parse many of these files through a loop, I don't know the value (e.g. "103") in advance - note in my example file above, it can only highlight the first part of the text that is static, and not the value which is unkown, unless done manually.

    If I somehow could highlight the entire line, I think the rest would be easy. I could just replace it with:

    1. add to string: <property name="Map ID" type="int" value="
    2. + add my new value
    3. + add to string: "/>

    I can experiment some more with string parser, and maybe check out the XML parser object

  • Thanks for a detailed answer. I guess my first issue is to successfully select the full line of text.
    Since I want to parse many of these files through a loop, I don't know the value (e.g. "103") in advance - note in my example file above, it can only highlight the first part of the text that is static, and not the value which is unkown, unless done manually.

    If I somehow could highlight the entire line, I think the rest would be easy. I could just replace it with:

    1. add to string: <property name="Map ID" type="int" value="
    2. + add my new value
    3. + add to string: "/>

    I can experiment some more with string parser, and maybe check out the XML parser object

    Yes, so you can easily load the whole file with String Parser 2 into a string, and then use the expressions discussed above on that string.

    • If you search for <property name="Map ID" type="int" value=" then you'll find the beginning character of the line you're trying to replace.
    • If you search from that spot for /> then you can find the end character of the line you're trying to replace.
    • Once you know the precise beginning and end of the line, you have all you need to replace the entire line, and nothing but that line.


    Though you should probably start with the XML parser object, as it sounds like it's designed for exactly your sort of use case.


    Another way to do it would be to load the whole file into a list object. The list object very much works with lines, not characters, so you could then easily search for the right line, and easily change the whole line. Which is closer to how you're currently imagining the process. But IIRC, loading a file into a list object is a pretty fiddly process on its own, requiring a fastloop setup. You can do it more easily with the Internal List Object. But start with the XML parser object, as that has the potential to be your easiest option.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!