Forum Discussion

bc1's avatar
bc1
Icon for Nimbostratus rankNimbostratus
May 15, 2017

Delete a substring

Hi,

I need to delete a substring from [HTTP::payload] before I pass it on for load-balancing but am running into problems with the error "char map list unbalanced ..

I need to strip two strings out completely and have tried using "string map" and "string replace" - this works fine when substituting for another string but not when substituting an empty string or tab / newline character ..

Surely there must be a simple way to do this ?!

Thanks!

e.g. the following works fine for "xyz" but fails for ""

set strSubstitute ""
set strSubstitute "xyz"
set strHTTPPayload [HTTP::payload]
set strHTTPPayload [ string map -nocase "$strOne $strSubstitute" $strHTTPPayload ]
set strHTTPPayload [ string map -nocase "$strTwo $strSubstitute" $strHTTPPayload ]
  • I've used this syntax before to remove spaces (%20) from URIs. Maybe you could use curly brackets instead of double quotes.

    set new_uri [string map {"%20" ""} $uri]