Hey guys, maybe you could help shed some light on an issue I ran into while running a program of mine tonight.

I have built countless programs around downloading webpage data and parsing it to retrieve data, but during a running of one of my programs tonight I got an error message. Well the error message happened due to a value equaling -1. Now I didn't put a check in there because that value should never equal -1.

But then I realized that my program had an issue. I have an if statement that contains a String.Contains check. The check triggered true, DESPITE the fact that the string I was checking for did not even remotely existing in the other string.

See, I even have a picture of the flaw (with some shotty photoshop work)
https://lh3.googleusercontent.com/-Z0avVqJiNCs/Ua8FABqfW_I/AAAAAAAADk4/p8mN6P7Atuw/s1680/StringContainTriggeringWrong_EDIT.png

So can someone help me out here. Did I just stumble on a bug, is this a known problem when using String.Contain or what cause right now this has me scratching head

Have you read what String.Contains actually does

Return Value
Type: System.Boolean
true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.

Have you actually checked that StartIndex is > 0, in the remove method check those parameters if they are > 0

Edited 3 Years Ago by Michael27

LOL oh I know what the error is, trust me.

The problem is, that it should have never gotten to that statement

For some reason, the String.Contains() said that

"http://cdn.steamcommunity.com/public/images/sharedfiles/steam_workshop_default_image.png>"

Contains

"<link rel=\"image_src\" href=\""

So yes I realize an error did occur, that returned a result of -1, I fully am aware of that, but the thing is, it should have never have gotten to that statement, as the String.Contains should not have returned true in any way.

I should note that I have run this program countless times, I mean this function alone has probably run thousands of times, yes thousands, as this is a parsing function. In fact, I am running right now, 1:46 run so far, 4417 results found, each one of those results has called this function

Edited 3 Years Ago by JOSheaIV

Well I ran the program again, and code crapped out again. Turns out String.Contains is working right, and I forgot that I altered the string, so infact is it working correctly.

So here's a piece of advice, don't code when you are running on little sleep.

This question has already been answered. Start a new discussion instead.