Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output a simple string that contains % symbol? #711

Closed
el-hoshino opened this issue Jul 6, 2021 · 1 comment · Fixed by #768
Closed

How to output a simple string that contains % symbol? #711

el-hoshino opened this issue Jul 6, 2021 · 1 comment · Fixed by #768

Comments

@el-hoshino
Copy link

el-hoshino commented Jul 6, 2021

For example, I need a string like this:

R.string.urls.url()"http%3A%2F%2Fwww.abc.xyz"

The tricky point is that R.swift only uses String(fromat: ...) initializer while there are parameters in the given string, so:

  1. If I apply the values like "url" = "http%%3A%%2F%%2Fwww.abc.xyz";, R.swift doesn't see any parameters, so treats it as a normal string, so the output is like "http%%3A%%2F%%2Fwww.abc.xyz"
  2. If I apply the value like "url" = "http%3A%2F%2Fwww.abc.xyz";, R.swift takes strings like %3A as parameters, and asks me to use the method like R.string.urls.url(Double, Double, Double)

One of the workarounds that my friend came out with is to use a dummy parameter like "url" = "http%%3A%%2F%%2Fwww.abc.xyz%@";, so we can use R.string.urls.url("") and the output is just what I wanted. But obviously it's just a workaround.

Is there any better way?

@digitalby
Copy link

I ended up doing this workaround to escape the percent sign in a string:
%\U200B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants