Compare nsurl or string in swift 2 - string

I am comparing two nsurl which are same but if condition is failing
if (url.absoluteString == self.currentPlayer?.currentAssetURL())
values
(lldb) po url.absoluteString
"Optional(https://a.t/y.mp3)"
(lldb) po self.currentPlayer?.currentAssetURL()
▿ Optional("https://a.t/y.mp3")
- Some : "https://a.t/y.mp3"
both urls are same but if condition is failing.
Please suggest.
Thanks in advance!

I found the answer. The problem was optional added inside the string and outside the string.
I fixed it.

Related

Splitting and parsing a String value in a pre-defined pattern in Groovy

Can someone please help me with how can a string value be converted into a predefined format by splitting the string?
For example:
If the
Stringvalue = "20210819"
needs to be converted as "08/19/2021"
(Splitting first four and then next two and again next two)
Thanks,
Thanks, #DaveNewton, I was able to do that as you suggested.
Stringvalue = "20210819"
valuedate=Stringvalue
valueyear=(valuedate[0..3]);
valuemonth=(valuedate[4..5]);
valueday=(valuedate[6..7]);
println (valuemonth+"/"+valueday+"/"+valueyear);

Reverting an addition to a string in PostrgreSQL

I followed the steps in this question
Append text to column data based on the column in PostgreSQL
But I made a mistake in the SIMILAR TO clause and the text got added to fields it shouldn't have. How can I reverse it?
Te query I ran was:
update metadatavalue set text_value = 'Fil: ' || text_value where metadata_field_id = 136 and text_value not similar to 'Fill:%';
How can I remove extre characters from those fields?
Thanks a lot in advance.
You can trim the prepended string off and update the column with the result:
UPDATE metadatavalue
SET text_value = regexp_replace(text_value, '^Fil: ','');

how to get the data in url using groovy code?

i want to get defect id from the url using groovy code (To build custom code in tasktop).
for example: I will have an dynamic url generated say www.xyz.com/abc/defect_123/ now I want to retrieve that letter that always starts from 17th position. and return the string
Please help..
Thanks in advance
Here are two possibilities. Please note that the "substring" option is very strict and will always start from the 16th position (what happens if the domain changes from www.xyz.com to www.xyzw.com?)
def str = 'www.xyz.com/abc/defect_123/';
def pieces = str.tokenize('/'); // prints defect_123
def from16 = str.substring(16); // prints defect_123/
println from16;
println pieces.last();
You should define this as dynamic url in UrlMappings.groovy file:
"www.xyz.com/abc/$defect_id" (controller: 'YourController', action: 'method_name')
and you can access the defect_id variable from YourController using params.defect_id

How to compare textfield.text and coredata attribute?

Here is my code..
NSLog(#"%#", [textField text]);
NsLog(#"%#", entity.attribute);
The log shows me The values
123 and 123 as the correct values..
But this code is not works
If([textField text] == entity.attribute) NSLog(#"Correct!");
The log "Correct!" is not shown..
What's the problem?? Help plz
You are comparing NSString* pointers, not their values... they are different objects.
If both are non-nil (might want to check for that), the following will work:
If([[textField text] compare:entity.attribute]==NSOrderedSame) NSLog(#"Correct!");

IndexOf bug when string contains 'AA'

I've run into a strange problem. I have a string with a value containing 'AA'.
I'm trying to find IndexOf the first accouring A. When I ask if the string Contains("A") it returns true. When using IndexOf("A") I keeps getting the default value -1! (se the picture below)
So far i tested there is only a problem with 'A' and 'a'.
When putting 3 a's in the string I get the index of number 3, as if the first two doesn't exsist.
When adding an extra a to the string, I get the default value -1 again.
I don't know what is causing this, I have a suspision that it's somehow connected to some langauge setting. I'm from denmark, and the use of the letters aa is a synonym for å.
Have anyone else experinced a simular problem or have a suggestion how to avoid it?
System information:
Windows 7 Ultimate (English)
Visual Studio 10 Premium
'aa' is handled as an entity if the culture is da-DK. The question is sort of a duplicate, see String StartsWith() issue with Danish text.
Hmmm I have tried the same now. It works...
static void XYZ()
{
string a = "aaa";
string b = "AAA";
if(a.Contains("a"))
{
Console.WriteLine(a.IndexOf("a"));
}
if(b.Contains("A"))
{
Console.WriteLine(b.IndexOf("A"));
}
}
But wouldn't it be the best to seach for a "aa" and "AA"? I can speak danish and I know that there are single a's too ;-)

Resources