In UIKit I used the same method to get only one part out of a long string and there it worked. However it dosen't work in swift ui app. I have wondered if it might be that it is not a string, but something else. Does anyone know a better solution to only get a short substring out of the long text?
let url = URL(string: "https://midcdmz.nrel.gov/apps/spa.pl?syear=2020&smonth=1&sday=1&eyear=2020&emonth=1&eday=1&otype=0&step=60&stepunit=1&hr=12&min=0&sec=0&latitude=39.743&longitude=-105.178&timezone=-7.0&elev=1829&press=835&temp=10&dut1=0.0&deltat=64.797&azmrot=180&slope=0&refract=0.5667&field=0")
struct ContentView: View {
var html = try! String(contentsOf: url!, encoding: String.Encoding.ascii)
let leftSideOfTheValue = "1/1/2020,0:00:00,"
let rightSideOfTheValue = "1/1/2020,1:00:00,"
guard let leftRange = html.range(of: leftSideOfTheValue) else {
print("cant find left range")
return
}
guard let rightRange = html.range(of: rightSideOfTheValue) else {
print("cant find right range")
return
let rangeOfTheValue = leftRange.upperBound..<rightRange.lowerBound
let elevationInfo = (html[rangeOfTheValue])
var body: some View {
Text(elevationInfo)
}