How to encode a text input for a URL?

Certified Senior Developer

We are searching with a text (example: "xyz pqr") and this input is passed to the integration to call API but API call fails because of the space in the input text/string.
Expected outcome: want to encode the input like "xyz%20pqr".

Note: Input may have any special characters including or other than spaces.

  Discussion posts and replies are publicly visible