See what characters are in an NSCharacterSet [duplicate] - swift

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.

Related

I would like to use a dollar sign in a flutter, how can I do this? [duplicate]

This question already has answers here:
Special characters in Flutter
(6 answers)
Closed 2 years ago.
I would like to use a dollar sign in a flutter, how can I do this?
like this:
Text('$21.99')
Use Escape Sequence Character,
Text('\$21.99')
You can use raw string by suffixing r.
Like this
Text(r'$21.99')

Swift 4 regex custom validation [duplicate]

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

best / quick way to remove character from string at a given index (swift 4) [duplicate]

This question already has answers here:
Remove nth character from string
(4 answers)
Closed 4 years ago.
I'm trying to remove the third character from a string. however, there does not seem to be a clean way to do this. I couldn't find an extension that does this and using a library is a bit overkill
I probably could take the first start range up to this character, then the last range and concatenating these together feels quite wrong and there must be a better way IMO
Any help is appreciated!, Thanks!
You can do that the below way:
var str = "I am Bla Bla"
if str.count > 2 {
str.remove(at: String.Index(encodedOffset: 2))
print(str)
}
Hope this helps.

How can I evaluate bool/arithmetic expression in Swift? [duplicate]

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.

How to eregi_replace to preg_replace [duplicate]

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 .