cancel
Showing results for 
Search instead for 
Did you mean: 

Parse username from server response

Squeak
Cirrus
Cirrus

Hi,

 

I´m trying to parse a username from a response that I´m receiving from a external server.

The complete response from the server·

HTTP/1.1 200 OK  Cache-Control: private  Content-Type: application/json; charset=utf-8  Server: Microsoft-IIS/10.0  X-AspNet-Version: 4.0.30319  X-Powered-By: ASP.NET  Date: Mon, 25 May 2020 10:18:21 GMT  Content-Length: 47    {"pid":"asdf001","mobileNumber":"+12345678909"}

I´m using "findstr" to search for the username.

set parse_user [findstr $recv_data "pid" 5 ","] log local0. " status ---->>>$parse_user"

The log local0. looks this

"asdf001"

 

My question is, how do I remove the quotes on both sides of the username?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Grumpy_Cat
Cirrus
Cirrus

Hi Squeak,

 

You can use string map to strip the double quotes.

set strip_quotes [string map {\" {}} $parse_user]

 

Kind regards

Ben

View solution in original post

3 REPLIES 3

Grumpy_Cat
Cirrus
Cirrus

Hi Squeak,

 

You can use string map to strip the double quotes.

set strip_quotes [string map {\" {}} $parse_user]

 

Kind regards

Ben

Hi,

 

I tried your solution and it worked!

Can you describe how this syntax {\" {}} removed the double quotes?

 

Thank you.

Grumpy_Cat
Cirrus
Cirrus

Hi Squeak,

 

http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M24

"If a backslash (“\”) appears within a word then backslash substitution occurs." -> "This allows characters such as double quotes, close brackets, and dollar signs to be included in words without triggering special processing."

 

In this example, we've substituted double quotes with an empty space {}. You can alternatively use double quotes for the second parameter:

set strip_quotes [string map {\" ""} $parse_user]

Kind regards

Ben