0

I am fairly new to C# Here I want to get the contents of List.txt and replace the GUID and Password from the list. The objective here is to replace the GUID and PASSWORD from each each line from the file List.txt List Format:

 Simpletest@humnianmai.com,Funkie312 
 Monkeies241@kubkdaw.com,Knuanh141
 Nuimabaiu@hgsa.gtv,jUbskj371

NOTE: I encrypt the data but this is just an example.

public class Log
{
    private const string UserList = @"C:\Server\UserManagement\list.txt";
    string contents = File.ReadLines(GUID);
    string contents = File.ReadLines(PASSWORD);


    private static readonly string URL = "https://www.mypersonaldomain.com/account/verify?guid=" + GUID + "&" + PASSWORD;

Update from comments

I need to take the contents list from the file List.txt and replace that in the

private static readonly string URL = "https://www.mypersonaldomain.com/account/verify?guid=" + GUID + "&" + PASSWORD;

I only need to replace GUID and PASSWORD but I do not know how to tell the code to read from the file and GUID,PASSWORD is seperated like Monkeies241@kubkdaw.com,Knuanh141 in the List.txt

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
Ryan Smith
  • 17
  • 6
  • 2
    Can you make this a little clearer, its not obvious what is in the lists, the files, and what you want to replace – TheGeneral Nov 24 '18 at 06:41
  • Revised.//10char – Ryan Smith Nov 24 '18 at 07:01
  • 2
    Your revisions didn't help one little bit. This is still extremely unclear, If you really wan people to help you, spend more than 10 seconds writing a question, be clear, explain what you want precisely to an audience who have no idea what your application is trying to do, show us what is not working, why you expect it to work, how you come up that logic, what you have tried. – TheGeneral Nov 24 '18 at 07:07
  • I need to take the contents list from the file List.txt and replace that in the `private static readonly string URL = "https://www.mypersonaldomain.com/account/verify?guid=" + GUID + "&" + PASSWORD;` I only need to replace GUID and PASSWORD but I do not know how to tell the code to read from the file and GUID,PASSWORD is seperated like Monkeies241@kubkdaw.com,Knuanh141 in the List.txt – Ryan Smith Nov 24 '18 at 07:22
  • Write the description from your last comment to the question. And must it be a code? For such a simple task I would use text editor with support of regex, e.g. Notepad2. – Julo Nov 24 '18 at 07:24
  • Ahh ok, also, and email address is not a GUID – TheGeneral Nov 24 '18 at 07:25
  • My API uses GUID for email data and the string I wrote needs to be replaced with the 'GUID' email from List.txt. Sorry for the confusion. – Ryan Smith Nov 24 '18 at 07:29
  • GUID is **not** an email address, for your reference [globally unique identifier GUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) **and** [Email address](https://en.wikipedia.org/wiki/Email_address) it does makes no sense to use these terms interchangeably – TheGeneral Nov 24 '18 at 07:31

1 Answers1

0
var lines = File.ReadLines("List.txt")
                .Select(x =>
                    {
                        var split = x.Split(',');
                        return $"https://www.mypersonaldomain.com/account/verify?guid={split[0]}&{split[1]}";
                    });

Additional Resources

String.Split Method

Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array.

Enumerable.Select Method

Projects each element of a sequence into a new form.

$ - string interpolation (C# Reference)

The $ special character identifies a string literal as an interpolated string. An interpolated string is a string literal that might contain interpolated expressions. When an interpolated string is resolved to a result string, items with interpolated expressions are replaced by the string representations of the expression results. This feature is available in C# 6 and later versions of the language.

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • I added your code...this does not replace anything and left out password... I checked with Fiddler my packet-sent look like this https://www.mypersonaldomain.com/account/verify?guid=& and I receive invalid response. Please help. – Ryan Smith Nov 24 '18 at 08:00
  • @RyanSmith the code is fine, your debugging skills are not though [Tutorial: Learn to debug using Visual Studio](https://learn.microsoft.com/en-us/visualstudio/debugger/getting-started-with-the-debugger?view=vs-2017) put a break point on the split and also inspect lines. afterwards – TheGeneral Nov 24 '18 at 08:03
  • you wrote var but I am using string for GUID and PASSWORD I am confused about how to fit your code with public static string GUID; public static string PASSWORD; and url – Ryan Smith Nov 24 '18 at 08:40