replace a character in a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • boudie
    Forum Member
    • Jun 2003
    • 3

    replace a character in a string

    I want to replace a character in a string that is located in a txt file. After installation there will be a test.txt file This file has a specific string (i already have a variable of this string) this string contains 2 back slashes and i want to replace these with 2 forward slashes. Thats all it has to do. Is there is a simple way of doing this?
  • Darryl
    Indigo Rose Staff Member
    • Jul 2001
    • 1908

    #2
    Re: replace a character in a string

    I'll point you in the general direction and provide the actions that you may want to use, however there's a variety of methods to accomplish this I'm sure.

    You may want to do the replacement line by line in the text file.
    -You could first use a "Count Text Lines" action to return the number of lines in the text file. This will be used to loop through the text file line by line.

    - Then use a Get Text Line action to read a line into a variable.

    - With each line, use the "Get Delimited string" action with "\\" as the delimiter. This will get a delimited string of all of the strings in between the "\\" characters.

    - You can then count that delimited string and loop through it creating a new string, ie. the delimited strings plus the new "//" characters. You can concatenate strings using the Assign Value action with the "+" operator.

    Then once you have the new string, you could delete that line in the text file and insert the new one. You will need at least two loops using While or IF control structures and some counters.

    It will take a little bit of work obviously, but give it a try working with small parts and moving your way up to a text file.

    Hope that helps.

    Comment

    • intel352
      Forum Member
      • Jan 2003
      • 81

      #3
      Re: replace a character in a string

      k, i'm having to do something similar (manipulation of a text file), but is there no way to use the information from the text file, after reading it into a variable?

      it seems to me it would be much faster to have the text file in a variable, but there's nothing delimiting the text once it's been put into that variable, other than whatever the symbol is for newline... which, i doubt is supported in SF6

      any idea?
      i've used the method you just suggested, in the past, but i'd like to speed performance and use the hdd less

      Comment

      • Darryl
        Indigo Rose Staff Member
        • Jul 2001
        • 1908

        #4
        Re: replace a character in a string

        What you could do is use the design-time constant defined as the following:

        **********************************
        #ASC????#
        This is a special set of design-time constants. When a constant's name starts with "#ASC", Setup Factory interprets the value assigned to that constant as the ASCII value of a character. Wherever you use that constant, Setup Factory replaces the constant's name with the corresponding character.

        For example, if you create a design-time constant named #ASC_QUOTE# and assign the value "34" to it, Setup Factory would replace each occurence of #ASC_QUOTE# in your project with the character whose ASCII number is 34, i.e., a quotation mark ("). Or, you could create a design-time constant to represent the null character (ASCII value 0) by assigning the value "0" to "#ASCNULL#".
        **********************************

        I believe the ASCII representation for the newline character is 10, so you should be able to use that as your delimiting character. You can define your design time constant in Project->Settings, Design-time Constants tab. Then use that variable every time you wish to refer to that character.

        Hope that helps.

        Comment

        • intel352
          Forum Member
          • Jan 2003
          • 81

          #5
          Re: replace a character in a string

          oooh, that sounds excellent!! imma go try it, hehe

          thanks for that tip! [img]/ubbthreads/images/icons/laugh.gif[/img]

          Comment

          • intel352
            Forum Member
            • Jan 2003
            • 81

            #6
            Re: replace a character in a string

            that worked perfectly [img]/ubbthreads/images/icons/wink.gif[/img]

            it added a null character to the end of each line, but i had the installer determine the length of the line, then subtract #ASC_NEWLINE#'s length from the total length, and used Left String to separate the line from the newline character [img]/ubbthreads/images/icons/smile.gif[/img]

            i think you guys would enjoy seeing some of the stuff i'm making this installer software do, hehe.. it's surprisingly versatile, now all we *really* need is the ability to create our own screens

            i'm looking forward to the release of sf7 [img]/ubbthreads/images/icons/wink.gif[/img]

            Comment

            • boudie
              Forum Member
              • Jun 2003
              • 3

              #7
              Re: replace a character in a string

              Well i think i will go look for something that does have a find/replace feature. I simply don't understand that there is STILL not such a feature available in this product. It has features that most users don't even use, but a simple find/replace cant be added? Thanks for your time anyways.

              Comment

              • Darryl
                Indigo Rose Staff Member
                • Jul 2001
                • 1908

                #8
                Re: replace a character in a string

                A search and replace action will be added in the future for sure. I can certainly help you out, however you'll need to meet me half way and let me know what you have tried and where you are having trouble. Each action also has a "Help" button that describes its functionality.

                Comment

                Working...
                X