Is there a way to determine if string does not contain something in an if statement? Basically the opposite of .contains .
Example of contains:
if someItem.contains(x) {
code
}
Example of what I am looking for:
if someItem.doesNotContain(x) {
code
}
Where a slolution for doesNotContain is what I am looking for.
Any help is greatly appreciated, thank you.
*FYI, I am new to Swift and to programming, thank you for your comments.
No Apple doesn't provide any function like doesNotContain or something similar.
But if you don't want to add else part then you can simply use:
if !someItem.contains("hello") {
//This means your someItem doesn't contain "hello" string.
}
try using this way
if !someItem.contains(x) {
code
}
Here are the results:
First off, I removed “without using a true/false Boolean” from my question in order to avoid confusion and to better suit the answer/solution.
Is there a code that is opposite to .contains? Simple Answer: NO.
It turns out that contains(_:) is a Boolean in of itself. This I did not know since I am new to coding.
The solution is actually quite simple as we can state this Boolean to be true or false, as suggested by #The Tiger.
if someItem.contains(x) == false
or
if someItem.contains(x)
Tested this, and works like a charm. Opens up a bunch of new oportunities for me, and I hope this helps out fellow coders in search of something like this.
Thank you all for your comments and helping me find the answer, Cheers.
Related
GAMS: I think I have a pretty simple question, however I'm stuck and was wondering if someone could help here.
A simplified version of my model looks like this:
set(i,t) ;
parameter price
D;
variable p(i,t)
e(i,t);
equations
Equation1
obj.. C=sum((i,t), p(i,t)*price);
Model file /all/ ;
Solve file minimizing C using MIP ;
Display C.l;
p(i,t) and e(i,t) are related:
Equation1 .. e(i,t)=e=e(i,t-1)+p(i,t)*D
Now I want to retrieve information from the solution: lets say I want to know at what t e(i,t) has a certain value for example --> e(i,t)= x(i) or otherwise formulated e(i,t=TD)=x(i) find TD, where x(i) thus is depending on i. Does anyone know how I can write this in to my GAMs model? To be clear I do not want to change anything about my solution and the model I have runs; I just want to retrieve this information from the solution given.
So far I tried a couple of thing and nothing worked. I think that this must be simple, can anyone help? Thank you!
Try something like this:
set i /i1*i10/
t /t1*t10/;
variable e(i,t);
*some random dummy "solution"
e.l(i,t) = uniformInt(1,10);
set find5(i,t) 'find all combinations of i and t for which e.l=5';
find5(i,t)$(e.l(i,t)=5) = yes;
display e.l,find5;
Hope that helps,
Lutz
I'm looking to return the number of results found in an ajax fashion on Algolia instant search.
A little field saying something like "There are X number of results" and refines as the characters are typed.
I've read you utilise 'nbHits' but i'm unsure of how to go about it.. Being from a design background.
Thanks for help in advance.
The instantsearch.js stats widget shows the number of results and speed of the search. If you don't want to use the widget, I believe you can still use {{nbHits}} inside of your template wherever you want the number to print.
Very easy when you know how, Thanks for pointing me in the right direction Josh.
This works:
search.addWidget(
instantsearch.widgets.stats({
container: '.no-of-results'
})
);
So, I'm developing an application in C and I need to sscanf a string.
+CPMS: \"ME\",18,255,\"ME\",18,255,\"ME\",18,255
I need to get the number between the first and second commas, 18 in this example, but it can be from 0 to 255.
I'm trying to create the placeholder to get this but I can't seem to make it work.
I've tried lots of thing, but I can't understand why:
sscanf(pointer, "+CPMS: \"%*s\",%d", &intPointer);
doesn't work.
Can anyone help me?
Thank you.
Well, I'm going to answer my own question.
sscanf(pointer, "+CPMS: \"%*2s\",%d", &intPointer);
It looks like I needed to put the number of characters to ignore.
Hope it help someone else.
I am using the XLFORM library with swift, I want to clear the value of the row after a successfully request .
I am trying to get the row object using self.form.formRowWithTag and changing the value using .value but unfortunately I am not able to get the row's object :(
anyone can help on this ?
I was searching for this answer as well, and your answer gave me inspiration.
What you have done so far is correct. Here is the code:
self.form.formRowWithTag("whatever-tag").value = nil
self.tableView.reloadData()
The key is to reload your UITableView
Hope this helps =)
While the above answer might work, I found out how to do it the way XLForm author wants you to do. On XLForm Github, the author says:
You may have to update the cell to see the UI changes if the row is
already presented. -(void)reloadFormRow:(XLFormRowDescriptor *)formRow
method is provided by XLFormViewController to do so.
So, you can do this:
var row = self.form.formRowWithTag("whatever-tag")
row.value = nil
self.reloadFormRow(row)
Hope this helps.
i am having trouble about json part of venues, in this picture i am trying to take the prefix and suffix, i am putting size between them but my problem is when i try to put them together the link of prefix + size + suffix comes like this -> i am taking prefix and suffix in seperate NSMutableArray's but when i try to join them together it's not working. and here is my way to join them.
where am i doing this wrong?
Are you sure that your objects in the imagePrefix and imageSuffix arrays are actually strings? Because judging from your logs it looks as if you're trying to concatenate two arrays and a string. If you let us know what is actually in those arrays you might get more helpful answers. You must be doing some conversion/manipulation from the original JSON, as in the API they get returned as dictionary items not arrays.
On a unrelated note, consider using fast enumeration (for id item in array) rather than writing out the for statement as you've done. Generally speaking it's also much better to post your code as text using markdown syntax rather than images: makes it much harder to copy/paste your code into an answer.
so thanks to "Matthias Bauch" i figured it out and here is my answer for my own question :)
for (int e = 0; e<=[imagePrefix count]-1; e++) {
NSLog(#"%#b_32%#", [[imagePrefix objectAtIndex:e] objectAtIndex:0], [[imageSuffix objectAtIndex:e] objectAtIndex:0]);
}
Thanks guys!