This question already has answers here:
How do I check if a string contains another string in Swift?
(28 answers)
Closed 7 years ago.
The answer in this question: How do I check if a string contains another string in Swift?
No longer works.
var string = "hello Swift"
if string.rangeOfString("Swift") != nil{
println("exists")
}
Will get you:
error: value of type 'String' has no member 'rangeOfString'
What is the new way to do this?
Import Foundation and you will be able to call rangeOfString.
Related
This question already has answers here:
Split string into array of characters?
(7 answers)
Closed 3 years ago.
can you help me on this?
I have a simple string:
str="Hello World";
I want to split it as that :
array= str.Split("",System.StringSplitOptions.RemoveEmptyEntries);
result shoud be
array[0]="H"
array[1]="e"
array[2]="l"
array[3]="l"
array[4]="o"
array[5]="W"
array[6]="o"
...
But I don't know to "wildcard" the separator..
Any Idea on this ?
Thanks
?
Just use String.ToCharArray():
SomeArray = str.ToCharArray()
This question already has answers here:
How do you print a dollar sign $ in Dart
(2 answers)
Closed 4 years ago.
I'm currently creating an simple application with flutter(Dart). And when i want to create the AppBar widget, i cant give it names with '$'. Because, same like Kotlin..Dart is using '$' for summoning an identifier.
Any solution?
var _appbar = AppBar(
title: Text("How I Made $100"), //$ is the error
);
The dollar sign is a special character, so if you want it to be ignored you have to escape it with a \.
For example:
void main() {
print("This string contains a dollar \$ign");
}
See this gist.
This question already has answers here:
Expand string Variable stored via Single Quote in Powershell
(2 answers)
Closed 5 years ago.
The first example below is a normal static string getting parsed. The second example is me attempting to do the same thing but get the string to parse live, dynamically. I need to know what to put in the place of (($myparse gets evaluated)) below in order to get it to parse the contents of $myparse on-the-fly. I'm sure it's some kind of script block, but I can't figure out what kind.
The following code correctly parses the static string as "Hello John Smith" and stores it in $mysalutation:
>$firstName = "John"
>$lastName = "Smith"
>$mysalutation = "Hello $firstName$(if($lastname) {" " + $lastName})."
>$mysalutation
Hello John Smith.
What I want to do is parse the same string on the fly:
>$myparse = 'Hello $firstName$(if($lastname) {" " + $lastName}).'
>$myparse
Hello $firstName$(if($lastname) {" " + $lastName}).
>$firstName = "Jason"
>$lastName = "Bourne"
>$mysalutation = (($myparse gets evaluated))
>$mysalutation
Hello Jason Bourne.
You are looking for the ExpandString function:
$ExecutionContext.InvokeCommand.ExpandString($myparse)
This question already has answers here:
How can I create a UILabel with strikethrough text?
(21 answers)
Closed 8 years ago.
How can I write a string like the following:
H̶̶o̶̶w̶ ̶t̶̶o̶ ̶w̶̶r̶̶i̶̶t̶̶e̶ ̶t̶̶h̶̶i̶̶s̶ ̶t̶̶e̶̶x̶̶t̶
In my app, I need to display the past price of a product that has been replaced by a new price. Like so:
$̶8̶̶0̶̶0̶ -> $600
To get this result you should use NSAttributedString and set the attribute name NSStrikethroughStyleAttributeName. The number used as object for this key defines the style of the line over the text.
self.myLabel.attributedText = [[NSAttributedString alloc] initWithString:#"800" attributes:#{NSStrikethroughStyleAttributeName: #1}];
Cheers
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
Please how can I correct this error:
Warning: Illegal string offset 'handler' in /home/***************/public_html/whois/phpwhois/whois.gtld.php on line 95
on the following code:
function parse($data, $query)
{
$this->Query = array();
$this->SUBVERSION = sprintf("%s-%s", $query["handler"], $this->HANDLER_VERSION);
$this->result = generic_parser_b($data["rawdata"], $this->REG_FIELDS, 'dmy');
Please check if $query is a string if it is then the code will not work. Make sure you pass $enquiry as an array or fire an exception.