DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for [Swift CODE] URLify
✨ thetealpickle πŸ“±
✨ thetealpickle πŸ“±

Posted on

[Swift CODE] URLify

THE TEAL PICKLE CODING CHALLENGE!! Replace all spaces on a string with β€˜%20'. I solved this problem with my lover, Swift. TRY IT πŸ‘€

QUESTION:

MY SOLUTION:

Top comments (2)

Collapse
 
tobiassn profile image
Tobias SN • Edited on

Uhhh...

string = string.replace(β€œ β€œ, β€œ%20”)

Or if you wanna go all in:

from urllib.parse import quote
string = quote(string)

(Snippets are in Python because I don’t know Swift)

Collapse
 
thetealpickle profile image
✨ thetealpickle πŸ“± • Edited on

Yeah in Swift 5 the syntax is pretty similar
string.replaceOccurrences(of: β€œ β€œ, with: β€œ%20”)

In everyday practice, I def use that method.

Typically in interviews, interviewers want to see whether the interviewee understands/can derive the algorithm which makes that method work (hence, all the code πŸ˜¬πŸ™ƒ)

Timeless DEV post...

How to write a kickass README

Arguably the single most important piece of documentation for any open source project is the README. A good README not only informs people what the project does and who it is for but also how they use and contribute to it.

If you write a README without sufficient explanation of what your project does or how people can use it then it pretty much defeats the purpose of being open source as other developers are less likely to engage with or contribute towards it.