Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 13 of 13

Thread: String Replace

  1. #1
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    Grin 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. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

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

  3. #3
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    Re: String Replace

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

  4. #4
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

    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.



  5. #5
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    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?

  6. #6
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

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

  7. #7
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    Re: String Replace

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

  8. #8
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

    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

  9. #9
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728

    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 ]]

  10. #10
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

    Re: String Replace

    True.

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

  11. #11
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728

    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 ]]

  12. #12
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959

    Re: String Replace

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

  13. #13
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728

    Re: String Replace

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts