This question already has answers here:
How do I encode/decode HTML entities in Ruby?
(8 answers)
Closed 6 years ago.
How can I extract the ascii code from a string and then convert it to char?
string = "a – b"
to
a – b
Use CGI library from ruby
CGI.unescapeHTML("a – b")
#=> "a – b"
Related
This question already has answers here:
Precision String Format Specifier In Swift
(31 answers)
Closed 2 years ago.
I need to transfer the double variable to the localization file, if I write %d I can only pass int, but I need to pass the double
You can pass the double with format string %f. To restrict the number of digits after the decimal point you can format is like this %0.2f. This will allow only 2 digits after the decimal point.
Sample Code:
let num = 10.5
let outputStr = String(format:"I am printing %0.1f", arguments:[num])
print(outputStr)
This question already has answers here:
How to capitalize each word in a string using Swift iOS
(8 answers)
Closed 5 years ago.
I want output like this:
var String1 = "stack over flow"
var desiredOutPut = "Stack Over Flow"
Also, I want this output in TextField event named "textFieldDidChange" so it must be efficient as well.
var desiredOutPut = String1.capitalized
This question already has answers here:
Finding out whether a string is numeric or not
(18 answers)
Closed 7 years ago.
How can I check, if searchView contains just numbers?
I found this:
if newText.isMatchedByRegex("^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$") { ... }
but it checks if text contains any number. How can I do, that if all text contains just numbers in Swift?
Here is the solution you can get all digits from String.
Swift 3.0 :
let testString = "asdfsdsds12345gdssdsasdf"
let phone = testString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
print(phone)
you can use "^[0-9]+$" instade "^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"
This will accept one or more digits, if you want to accept only one digit then remove +
This question already has answers here:
Convert erlang terms to string, or decode erlang binary
(2 answers)
Closed 9 years ago.
Is there a way how to convert a tuple to a string ?
Consider I have the following list :
[{atom,5,program},{atom,5,receiving},{nil,5}]
I wish to convert this into the following string:
"{atom,5,program},{atom,5,receiving},{nil,5}"
I have tried using erlang:tuple_to_list on each element in the list, which returns
A = [atom,5,program]
Eventually, I can't concatenate that with "{" ++ A ++ "}"
Any ideas how I can turn that to a string ?
Term = [{atom,5,program},{atom,5,receiving},{nil,5}].
lists:flatten(io_lib:format("~p", [Term])).
This question already has answers here:
How to escape double quotes in string?
(3 answers)
Closed 10 years ago.
I have a string that has multiple " in it, which is written inside of #"" and of course, xcode sees this as me ending the #". Is there any alternatives I can use for #"" that would do the same thing?
It's done with escape chars. #"My name is \"Someone\". Blabla.";