Read .txt each line stream and REPLACE string values separated by [,] comma

182 Views Asked by At

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:

 [email protected],Funkie312 
 [email protected],Knuanh141
 [email protected],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 [email protected],Knuanh141 in the List.txt

1

There are 1 best solutions below

3
On
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.