PDA

View Full Version : String Replace


Bruce
09-08-2003, 01:21 PM
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?

Worm
09-08-2003, 01:57 PM
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...

Bruce
09-08-2003, 03:56 PM
Sorry Worm, It's not working for me, can you give me a small example?

Worm
09-08-2003, 04:05 PM
Here you go (http://www.warmuskerken.com/ams/replace.zip)

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.

Bruce
09-08-2003, 09:26 PM
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?

Worm
09-08-2003, 09:49 PM
you could use a loop and replace every instance of 2 spaces with one until you don't get a hit on 2...

Bruce
09-08-2003, 09:53 PM
OK, without building it for me, what action/actions do I use?

Worm
09-08-2003, 09:59 PM
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

Lorne
09-09-2003, 09:52 AM
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.

Worm
09-09-2003, 09:55 AM
True.

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

Lorne
09-09-2003, 09:58 AM
In that case just loop the last step (replace 2 spaces with 1) until it fails to find any pairs of spaces.

Worm
09-09-2003, 10:36 AM
I believe that is what I suggested /ubbthreads/images/icons/smile.gif

Lorne
09-09-2003, 10:39 AM
Yep. /ubbthreads/images/icons/smile.gif