This question already has answers here:
Swift string formula into a real calculation
(3 answers)
Swift - Resolving a math operation in a string
(4 answers)
Closed 6 years ago.
How can I eval a string in Swift?
My strings are composed by numbers and logic operators.
Some examples are:
"2+2"
"2%2"
"2+2"
"2=3"
"2>3"
"2/5"
I've thought, if is too complex to write a function to do this, to parse a string and execute that as external process in bin/bash process than read a result. Any ideas?
Other questions, like this, are solution if there are only arithmetics operators. In my cases appears bool operators that returns error in NSExpression eval.
Related
This question already has answers here:
Rounding a double value to x number of decimal places in swift
(34 answers)
Closed 3 years ago.
I am trying to reduce the amount of characters in a double. How Would I reduce this:
59.5220000
to
59.5
this in swift?
A double doesn't have characters. A string rendering of it does. Rather than using the standard String() initializer (which is really only for development use, it's terrible for end-users), use NumberFormatter.
perhaps use a formatted string?
let str = String(format: "%.2f", 59.5220000)
This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 4 years ago.
i need some help to write correct regex validation. I want password with no spaces, min. 6 symbols, doesn't matter numbers or letters or symbols. Alphabet a-zA-Z and а-яА-Я(RU). How i can do that?
"^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{6,}$"
You can take a look at this link
This question already has answers here:
How String Comparison happens in Swift
(4 answers)
What does it mean that string and character comparisons in Swift are not locale-sensitive?
(3 answers)
Closed 5 years ago.
Documentation > Swift > ClosedRange
let values = "a"..."z"
print(values.contains("c")) //true
Could someone please explain why this prints true?
This question already has answers here:
NSArray from NSCharacterSet
(9 answers)
Closed 7 years ago.
When I'm trying
print(NSCharacterSet.URLQueryAllowedCharacterSet())
it prints
<__NSCFCharacterSet: 0x1759b900>
How do I make it more informative?
You can get a representation of the character set using bitmapRepresentation which could be queried. Or you could do basically the same thing with a loop over all characters and using characterIsMember:. The output is potentially big...
There isn't really a simple option or a generic concise output to what you're asking for. It isn't a common requirement.
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 8 years ago.
eregi_replace('[0-9]+\.+[0-9]','',$cart['unit']);
How to change it to preg_replace?
I get an error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '+' in ---
You can use your existing Regex almost unchanged in a preg_replace(). Just add delimiters and a case-insensitive modifier. You get
preg_replace('#[0-9]+\.+[0-9]#i','',$cart['unit']);
In fact, the case-sensitivity is irrelevant since your pattern only matches 0-9 and .