C
C#2y ago
Jin

❔ Downloading string from webclient isnt responding properly to my if statement.

So im trying to make a version check by grabbing the data from a raw github link, it gets the data but my if statement isnt detecting it properly. Its most likely the downloaded string is breaking or something but i have no clue.
23 Replies
Thinker
Thinker2y ago
Don't use WebClient
Jin
JinOP2y ago
what would i use?
Thinker
Thinker2y ago
HttpClient
FusedQyou
FusedQyou2y ago
To clarify: HttpClient is the modern webclient and works better for fetching/sending data.
Thinker
Thinker2y ago
HttpClient client = new();
var response = await client.GetAsync(url);
var download = await response.Content.ReadAsStringAsync();
HttpClient client = new();
var response = await client.GetAsync(url);
var download = await response.Content.ReadAsStringAsync();
Axiss
Axiss2y ago
What is VersionText.Text?
Thinker
Thinker2y ago
Probably a WinForms label or something
Axiss
Axiss2y ago
Sure, but what is the value?
Jin
JinOP2y ago
the value is 0.1.3 same goes for the github im just trying to test if the messagebox pops up but it doesnt.
Axiss
Axiss2y ago
Check to see if the string from github has a linefeed or something at the end
Jin
JinOP2y ago
Jin
JinOP2y ago
it didnt.
Axiss
Axiss2y ago
Jin
JinOP2y ago
huh
Axiss
Axiss2y ago
Don't know if that's just chrome view-source UI thing, but check it with the debugger just in case
Jin
JinOP2y ago
yeah in github it does show that but i cant make it one.
Thinker
Thinker2y ago
Try trimming the whitespace first before comparing
Axiss
Axiss2y ago
Version.Parse Method (System)
Converts the specified read-only span of characters that represents a version number to an equivalent Version object.
Jin
JinOP2y ago
Trimming worked!
Axiss
Axiss2y ago
Comparing raw strings it's always a good idea to trim them. Very easy to accidently get non-visible whitespace in there screwing with you
Jin
JinOP2y ago
Alright, something new i learned 🙂
Axiss
Axiss2y ago
I still recommending parsing them into a Version, it will make the comparison easier No need to roll your own
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server