Announcement

Collapse
No announcement yet.

String Replace

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • String Replace

    I am copying the contents of a text file to a variable and then running a String Replace to get rid of the ;; and ::. This is what the text looks like now:

    Example:
    Selected Answers - What's after 17?;;18;;What's after 13?;;14;;What's after 19?;;20;;What's after 6?;;7;;What's after 4?;;5;;What's after 7?;;8;;What's after 9?;;10;;What's after 18?;;19;;What's after 2?;;3;;What's after 10?;;4

    Wrong Answers - What's after 10?;;4

    I can get rid of the :: and the ;; no problem… It’s adding the space and doing a carriage return.

    Example:
    Selected Answers -
    What's after 17? 18
    What's after 13? 14
    What's after 19? 20
    What's after 6? 7
    What's after 4? 5
    What's after 7? 8
    What's after 9? 10
    What's after 18? 19
    What's after 2? 3
    What's after 10? 4

    Wrong Answers -
    What's after 10? 4

    Any ideas on adding a space and carriage return?

  • #2
    Re: String Replace

    Replace every instance of "?;;" with "? "

    Then replace every intance of ";;" with #ASC_CR##ASC_LF#

    The #ASC_CR# should be setup as a constant with a value of 13

    The #ASC_LF# should be setup as a constant witha value of
    10

    That should do ya...

    Comment


    • #3
      Re: String Replace

      Sorry Worm, It's not working for me, can you give me a small example?

      Comment


      • #4
        Re: String Replace

        Here you go

        This doesn't seperate the First line from the questions, but you can do that easy enough with delimited strings. Its all I have time to crank out for right now.


        Comment


        • #5
          Re: String Replace

          Thx worm, now I understand!
          This is what I have added:

          <IR_ACTIONS_LIST>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%ObjectText%</SearchIn>
          <SearchFor>?;;</SearchFor>
          <ReplaceWith>? </ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%NewString%</SearchIn>
          <SearchFor>;;</SearchFor>
          <ReplaceWith>#ASC_CR##ASC_LF#</ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%NewString%</SearchIn>
          <SearchFor>?::</SearchFor>
          <ReplaceWith>? </ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%NewString%</SearchIn>
          <SearchFor>::</SearchFor>
          <ReplaceWith>#ASC_CR##ASC_LF#</ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%NewString%</SearchIn>
          <SearchFor>?-</SearchFor>
          <ReplaceWith>? </ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          <Action name="Replace">
          <Type>60</Type>
          <Function>0</Function>
          <DTIndentLevel>0</DTIndentLevel>
          <Enabled>1</Enabled>
          <ErrorHandling>
          <UserNotificationMode>2</UserNotificationMode>
          <CustomErrorMessage/>
          <OnErrorAction>0</OnErrorAction>
          <JumpToLabel/>
          </ErrorHandling>
          <Variable>%NewString%</Variable>
          <SearchIn>%NewString%</SearchIn>
          <SearchFor>-</SearchFor>
          <ReplaceWith>#ASC_CR##ASC_LF#</ReplaceWith>
          <CaseSensitive>1</CaseSensitive>
          </Action>
          </IR_ACTIONS_LIST>

          Is there any verbage that allows me to take away say, six spaces?

          Comment


          • #6
            Re: String Replace

            you could use a loop and replace every instance of 2 spaces with one until you don't get a hit on 2...

            Comment


            • #7
              Re: String Replace

              OK, without building it for me, what action/actions do I use?

              Comment


              • #8
                Re: String Replace

                Do a String.Find on a double space.
                If there is a hit, then
                Do While the Find results do not equal to -1
                String.Replace to replace double space with a single
                Then check again for a hit on a double space
                Loop

                Comment


                • #9
                  Re: String Replace

                  Or do a bunch of consecutive replaces...replacing 6 spaces with 1, then 5 spaces with 1, then 4 spaces with 1...all the way down to replacing 2 spaces with 1.

                  --[[ Indigo Rose Software Developer ]]

                  Comment


                  • #10
                    Re: String Replace

                    True.

                    I was thinking the loop would take care of any extra spaces.

                    Comment


                    • #11
                      Re: String Replace

                      In that case just loop the last step (replace 2 spaces with 1) until it fails to find any pairs of spaces.
                      --[[ Indigo Rose Software Developer ]]

                      Comment


                      • #12
                        Re: String Replace

                        I believe that is what I suggested [img]/ubbthreads/images/icons/smile.gif[/img]

                        Comment


                        • #13
                          Re: String Replace

                          Yep. [img]/ubbthreads/images/icons/smile.gif[/img]
                          --[[ Indigo Rose Software Developer ]]

                          Comment

                          Working...
                          X