How to do string replace and cast to int

50 views
Skip to first unread message

Dolly Gyanchandani

unread,
Feb 17, 2023, 1:36:24 AM2/17/23
to CEL Go Discussion Forum
Hello folks,

I'm using KrakenD and "validation/cel". I'm trying to do a string replace, followed by a cast to integer. I'm struggling with the syntax, could someone help me figure what's wrong with it, or point me to good documentation available?

This is what I'm trying- 

"check_expr": "req_headers['X-Device-Version'][0].replace('.', '') == '940'"

Any help is really appreciated.

Thanks in advance

Tristan Swadell

unread,
Feb 17, 2023, 1:43:07 PM2/17/23
to Dolly Gyanchandani, CEL Go Discussion Forum
Hi Dolly,

I'm not super familiar with the setup for KrakenD, but could you tell me what issue you're encountering? Did you want to compare against an int rather than a string? Or is there some other experience or error that you're encountering?

If you want to convert a string to an int you'd use the `int()` conversion method:

int(req_headers['X-Device-Version'][0].replace('.', '')) == 940

Hopefully this helps, and if not, I can probably help more if you could share more details about what you're trying to do and what's not behaving as expected.

Cheers,

-Tristan

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/de75958f-7baa-4c4b-92d2-11aacb2b1798n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages