How to remove tab [CR][LF]character from String()?

For example, inside a json return from a webservice, there is a “tab” before the json{}, I tried using left() but it did not work.
Does anyone know how to do it?
thanks
06013a79-4719-47cf-ab4f-2e33e398865f

This Tab disturbs the component that reads the json{} and the component returns an error…

If you have StringTheory, then look at the .Replace method.
st.Replace(‘<09>’,‘’) !tabs
st.Replace(‘<0Dh,0Ah>’,‘’) ! CR/LF

If you don’t have StringTheory, you can check out the SystemStringClass.Replace that comes with C10 or newer.

If you don’t have that, then you’ll need to use a loop and InString to find and replace the occurrences.

The filtering characters is not a complex task. The FilterClass in following test program
test.clw (3.5 KB)
allows to set characters which must be filtered from a string.

1 Like

Woohoo!
I found!

 str.SetValue(stReturn)
 stReturn = **str.left(,st:cr + st:lf + st:tabs + st:spaces)**

Thank you all

1 Like

Something wrong in your way of a service response retrieving.

Good morning my friend Mikee!
I use the same method to retrieve for all WS, the problem is that the return of this specific WS comes with CR/LF before Json, using st.Left( ,st:cr + st:lf + st:tabs + st :spaces) from stringTheory, it is possible to remove this.
But if there is another method I’m happy to learn!!

Hugs

I think what Mike is sayings, is that whatever is consuming your JSON and throwing errors because of the tab and cr/lf characters is the problem.
Tab and CR/LF are valid whitespace in a JSON string. Just try it with any JSON validator and it passes.

This is one of my favorite techniques, and it has more than one type of use.
In addition to a filter, it makes for a nice substitution matrix (for example, substituting only “legal” characters for a file name or label).

Almost all algorithms were invented in the 60s and early 70s… I was lazy and used bytes as an element type for the map array. Bitmaps are enough for filtering. And, judging by the call parameters, the StringTheory class uses the bitmap for replacing. The question only in handling of the text in quotes and other kinds of brackets where it must be taken as is.

It’s not actually as simple as that. According to json.org, json begins with either a { or a [. You can end up with whitespace between names / values, but strictly not before or after the JSON document itself.

To be fair there are lots of JSON specifications, and of course pretty much any parser will simply ignore whitespace before the first { or [, but it’s not clear-cut to say “json allows it”.

Equally you are not allowed to have tab, CR or LF inside a string label or value. Those are encoded as \t, \r and \n.

Agreed. Jorge’s example showed the tab character “outside” of the JSON data. That’s what I was running with. :slight_smile: