Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Get string between 2 strings in a string

I am getting a string from html parse that is;

string = "javascript:getInfo(1,'Info/99/something', 'City Hall',1, 99);" 

my code is something like

var startIndex = text.rangeOfString("'") var endIndex = text.rangeOfString("',") var range2 = startIndex2...endIndex substr= string.substringWithRange(range) 

i am not sure if my second splitting string should be "'" or "',"

i want my outcome as

substr = "Info/99/something" 
like image 254
Alp Avatar asked Jul 30 '15 13:07

Alp


People also ask

How to check for string and character equality in Swift?

Sponsor sarunw.com and reach thousands of iOS developers. In Swift, you can check for string and character equality with the "equal to" operator ( ==) and "not equal to" operator ( != ). We use the same operator for Character. These "equal to" operator is suitable for simple string comparison where you required an exact match.

How to compare two strings ignoring their cases in JavaScript?

This would convey a message that you want to compare two strings ignoring their cases ( .caseInsensitive ). street.compare(alsoStreet, options: .caseInsensitive) == .orderedSame While this means the lowercase form of two strings should be equals.

Is the lowercase form of two strings equal?

While this means the lowercase form of two strings should be equals. Very different, right? I might be wrong about the meaning and assumption of the word "Straße" because I don't know German.


1 Answers

extension String {          func slice(from: String, to: String) -> String? {         return (range(of: from)?.upperBound).flatMap { substringFrom in             (range(of: to, range: substringFrom..<endIndex)?.lowerBound).map { substringTo in                 String(self[substringFrom..<substringTo])             }         }     } }  "javascript:getInfo(1,'Info/99/something', 'City Hall',1, 99);"   .sliceFrom("'", to: "',") 
like image 63
oisdk Avatar answered Sep 21 '22 15:09

oisdk