This is the first time I'm working with an API and I have used httpClient.getAsync(uri) to get a response in form of a CSV.
.
I'm wondering how to trim or delete parts of it to get a hold of some values. I've tried splitting it using ';' but There is so much clutter and none of what I have tried so far has worked. The 4 values I'm trying to get here are 65.7, 45.3, 64.4, 111.1 and all are located between 2 of these ';' in the middle of the file. In the form of a CSV file, it would be the column 3 (0-3) that I want.
httpClient.BaseAddress = new Uri("https://opendata-download-metobs.smhi.se/api.json");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using (HttpResponseMessage response = await httpClient.GetAsync(new Uri("https://opendata-download-metobs.smhi.se/api/version/latest/parameter/23/station/53430/period/latest-months/data.csv")))
{
res = MakeReadable(response);
Console.WriteLine(res);
noteMessage(ConsoleColor.Red, "Csv Processing");
string s = res.Substring(res.LastIndexOf("Från"));
Console.WriteLine(res);
Console.WriteLine(
response.IsSuccessStatusCode
? "Verification successful"
: $"Verification failure: {response.ReasonPhrase}");
}
}
The MakeReadable looks like this:
public static string MakeReadable(HttpResponseMessage apiResponse)
{
string temp = "";
HttpContent responseContent = apiResponse.Content;
Task<string> results = responseContent.ReadAsStringAsync();
temp = results.Result;
return temp;
}
What I don't understand is what Method to use. I have tried using .Remove() with a start and an end but it does nothing. I've tried cleaning strimg of everything but digits, but then i end up with a lot of numbers which also fails me. In the code above I even try Substring + LastIndexOf just to remove unneccessary parts of the string, but nothing works.