How to get data from each row of website (DownloadString) by after : char and stop till ; char

89 Views Asked by At

I use WebClient and DownloadString to get RAW text file into an string, and I would like to get the first words, like each thing before : char in to a string, AND also the stuff after : but before ; in other string. In this case I want word111 and floor271 in seperate string, and table123 and fan891 into an other string.

The text file looks like this:

word111:table123;
floor271:fan891;

I've tried to look around for days, because I use in my code the Contains method to see if the whole line of text sometimes matches, example word111:table123; if that exists in the raw text file, then the code continues. I looked at Split, IndexOf, and things like that but I don't understand if they can even achieve this goal, because I need them from every row/line, not just one.

WebClient HWIDReader = new WebClient();

string HWIDList = HWIDReader.DownloadString("/*the link would be here, can't share it*/");

if (HWIDList.Contains(usernameBox.Text + ":" + passwordBox.Text))
{
/* show other form because username and password did exist */
}

I expect the code wouldn't work with Split, because it can split the string by : and ; characters tho, but I don't want the usernames and passwords visible in the same string. IndexOf would delete before or after specified characters tho. (Maybe can use IndexOf to both ways? to remove from : till ; is that possible, and how?) Thank you in advance.

1

There are 1 best solutions below

0
holly_cheng On

You can split the string based on the newline character.

string HWIDList = HWIDReader.DownloadString("/*the link would be here, can't share it*/");
string[] lines = HWIDList.Split('\n');
// NOTE: Should create a hash from the password and compare to saved password hashes 
// so that nobody knows what the users' passwords are
string userInput = string.Format("{0}:{1};", usernameBox.Text, passwordBox.Text);
foreach (string pair in lines)
{
    if (pair != userInput)
        continue;

    // found match: do stuff
}