Code: Select all
{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}
Code: Select all
{}123{keep}
https://stackoverflow.com/questions/239 ... o-brackets
Appreciate any help.
Code: Select all
{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}
Code: Select all
{}123{keep}
Code: Select all
If CreateRegularExpression(0, "\{-.*?\}")
Define Result.s = ReplaceRegularExpression(0, "{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}", "")
Debug Result
Else
Debug RegularExpressionError()
EndIf
Code: Select all
Procedure.s Remove(*TextPtr.Character)
Protected Result$, Help$, State.i
While *TextPtr\c
Help$ + Chr(*TextPtr\c)
Select State
Case 0
If *TextPtr\c = '{'
State = 1
Else
Result$ + Help$
Help$ = ""
EndIf
Case 1
If *TextPtr\c = '-'
State = 2
ElseIf *TextPtr\c = '}'
Result$ + Help$
Help$ = ""
State = 0
EndIf
Case 2
If *TextPtr\c = '}'
Help$ = ""
State = 0
EndIf
EndSelect
*TextPtr + 2
Wend
ProcedureReturn Result$
EndProcedure
Text$ = "{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}"
Debug Remove(@Text$)
Code: Select all
If CreateRegularExpression(0, "{-.*?}")
Define Result.s = ReplaceRegularExpression(0, "{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}", "")
Debug Result
Else
Debug RegularExpressionError()
EndIf
Code: Select all
{}123{keep}
Code: Select all
; -------12345678901234567890123456789012345678901234567890
Text$ = "{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}"
; Expected
; {}123{keep}
Debug "Text: " + Text$
Nb = CountString(Text$, "{-")
Debug "Found: {-*} " + Nb + " time(s)"
For i = 1 To Nb
Debug #CRLF$ + "#" + i
STX = FindString(Text$, "{-")
If STX > 0
Debug " STX: " + STX
ETX = FindString(Text$, "}", STX)
Debug " ETX: " + ETX
Text$ = RemoveString(Text$, Mid(Text$, STX, ETX-STX+1))
STX = 0
EndIf
Next
Debug #CRLF$ + "Result: " + Text$
Code: Select all
Procedure.s Remove4(Text$)
STX = 1
Repeat
STX = FindString(Text$, "{-", STX)
If STX
ETX = FindString(Text$, "}", STX)
Text$ = RemoveString(Text$, Mid(Text$, STX, ETX-STX+1))
Else
Break
EndIf
ForEver
ProcedureReturn Text$
EndProcedure
Code: Select all
text$="abc {?913} --- {?9745} xyz"
While FindString(text$,"{?")
startPos = FindString(text$, "{?")
endPos = FindString(text$, "}")
text$ = Left(text$, startPos - 1) + Mid(text$, startPos + 2, endPos - startPos - 2) + Mid(text$, endPos + 1)
Wend
Debug text$ ; abc 913 --- 9745 xyz
Code: Select all
Procedure.s RemoveMarkers(*TextPtr.Character)
Protected Result$, Help$, State.i
While *TextPtr\c
Help$ + Chr(*TextPtr\c)
Select State
Case 0
If *TextPtr\c = '{'
State = 1
Else
Result$ + Help$
Help$ = ""
EndIf
Case 1
If *TextPtr\c = '?'
State = 2
ElseIf *TextPtr\c = '}'
Result$ + Help$
Help$ = ""
State = 0
EndIf
Case 2
If *TextPtr\c = '}'
Help$ = ""
State = 0
EndIf
EndSelect
*TextPtr + 2
Wend
ProcedureReturn Result$
EndProcedure
Text$="abc {?913} --- {?9745} xyz"
Debug RemoveMarkers(@Text$)
I want to convert abc {?913} --- {?9745} xyz to abc 913 --- 9745 xyz. As you can see, I just want to remove any leading "{?" and the closing "}" after it. These markers will be present multiple times in the string.
Code: Select all
EnableExplicit
Define Txt$ = "abc {?913} --- {?9745} xyz"
Debug Txt$
Txt$ = ReplaceString(Txt$, "{?", "")
Txt$ = ReplaceString(Txt$, "}", "")
Debug Txt$
End
Code: Select all
abc {?913} --- {?9745} xyz
abc 913 --- 9745 xyz
Code: Select all
Txt$ = "abc} {?913} --- {?9745} } } } {?xyz"
Txt$ = ReplaceString(Txt$, "{?", "")
Txt$ = ReplaceString(Txt$, "}", "")
; Next line debugs the wrong answer.
Debug Txt$ ; abc 913 --- 9745 xyz
Code: Select all
Txt$ = "abc} {?913} --- {?9745} } } } {?xyz"
Pos1 = FindString(Txt$, "{?")
While Pos1
Pos2 = FindString(Txt$, "}", Pos1)
If Pos2
Txt$ = Left(Txt$, Pos1 - 1) + Mid(Txt$, Pos2 + 1)
Else
Break
EndIf
Pos1 = FindString(Txt$, "{?", Pos1)
Wend
Debug Txt$
Code: Select all
Procedure.s CutOut(String$, CutStart$, CutEnd$)
Protected.i Pos1, Pos2, CutEndLen
CutEndLen = Len(CutEnd$)
Pos1 = FindString(String$, CutStart$)
While Pos1
Pos2 = FindString(String$, CutEnd$, Pos1)
If Pos2
String$ = Left(String$, Pos1 - 1) + Mid(String$, Pos2 + CutEndLen)
Else
Break
EndIf
Pos1 = FindString(String$, CutStart$, Pos1)
Wend
ProcedureReturn String$
EndProcedure
Txt$ = "abc} {?913} --- {?9745} } } } {?xyz"
Debug CutOut(Txt$, "{?", "}")
Txt$ = "{}{-first}1{-two}2{-three}3{-hello}{-last}{keep}"
Debug CutOut(Txt$, "{-", "}")