udfStrUnQuote
str udfStrUnQuote (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrUnQuote (strString, intMode)
If strString == "" Then Return strString
If intMode < 0 || intMode > 5 Then Return strString
intLen = StrLen (strString)
strCharL = StrSub (strString, 1, 1)
strCharR = StrSub (strString, intLen, 1)
strCharsLR = strCharL : strCharR
strQuoteChars = """""''``"
strBracketChars = "(){}[]<>"
Select intMode
Case 0
   strCharSet = strQuoteChars
   Break
Case 1
   strCharSet = strBracketChars
   Break
Case 2
   strCharSet = strQuoteChars : strBracketChars
   Break
Case 3
   strCharSet = strCharL : strCharL
   Break
Case 4
   strCharSet = strBracketChars : strCharL : strCharL
   Break
Case 5
   strCharSet = strCharsLR
   Break
EndSelect
blnRemove = @FALSE
intPos = 1
While !(blnRemove || (intPos > StrLen (strCharSet) / 2))
   blnRemove = ("" == StrClean (strCharsLR, StrSub (strCharSet, intPos + intPos - 1, 2), "", @FALSE, 1))
   intPos = intPos + 1
EndWhile
If blnRemove Then strString = StrSub (strString, 2, intLen - 2)
Return strString
;..........................................................................................................................................
; This UDF "udfStrUnQuote" removes quotation delimiters, brackets or any first/last chars.
;
; intMode = 0 ... Remove quotes only.
; intMode = 1 ... Remove brackets only.
; intMode = 2 ... Remove quotes and brackets.
; intMode = 3 ... Remove quotes and first/last chars if equal.
; intMode = 4 ... Remove brackets and first/last chars if equal.
; intMode = 5 ... Remove any first/last chars.
;..........................................................................................................................................
; (c)Detlev Dalitz.20010722.20100124.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; strFunc.

; Example 1.
intMode = 0
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = """'`[{<#test#>}]`'"""
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 1, Remove quotes only.", strOut)
   strIn = strTmp
Next


; Example 2.
intMode = 1
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = "[{<'`#test#`'>}]"
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 2, Remove brackets only.", strOut)
   strIn = strTmp
Next


; Example 3.
intMode = 2
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = """'`[{<#test#>}]`'"""
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 3, Remove quotes and brackets.", strOut)
   strIn = strTmp
Next


; Example 4.
intMode = 3
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = """'`#+[{<test>}]-#`'"""
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 4, Remove quotes and first/last chars if equal.", strOut)
   strIn = strTmp
Next


; Example 5.
intMode = 4
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = "[{<#'`test`'#>}]"
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 5, Remove brackets and first/last chars if equal.", strOut)
   strIn = strTmp
Next


; Example 6.
intMode = 5
strFunc = "udfStrUnQuote (strIn, " : intMode : ")"
strIn = """'`[{+<#test#>-}]`'"""
intSteps = 10
For intI = 1 To intSteps
   strTmp = udfStrUnQuote (strIn, intMode)
   intStatus = !!StrCmp (strIn, strTmp)
   strStatus = "Status: " : ItemExtract (1 + intStatus, "not changed.,changed.", ",")
   If intStatus
      strReplaced = StrReplace (strIn, strTmp, "")
      strStatus = strStatus : " " : ItemExtract (1 + intStatus, ",Chars=" : strReplaced, ",")
   EndIf
   strOut = strIn : @TAB : "-->" : @TAB : strTmp
   strOut = strFunc : @LF : "step " : intSteps : "/" : intI : @LF : @LF : strOut : @LF : @LF : strStatus
   Pause ("Ex. 6, Remove any first/last chars.", strOut)
   strIn = strTmp
Next

:CANCEL
Exit