c# compare 2 files see what they have the same and edit values depending on the file loaded RRS feed

  • Question

  • ok what i have is 2 files some share the same keys and i want to change the values so the file i want to load is like this 

    this is the file i want to load

    i know this can be done with a simple string split into dictuanry via // 

    this is the file i want to check to see what the same lines are 

    like i load in the top file it compares the 2 looks for like displayname this is example 

    and if finds changes the value of the one comparing to to the loaded ones value 

    this is the file i want to change the values on 

    also want the option to add it manually thats why im trying to load the first one into a dicunary so i can do something like this 


    or have it this way 

    filetochange["DisplayName"] = loadedfile["Displayname"]

    then once the file changes all thats needed i want to save the filetochange to a file called like output.gdt

    i hope i explained that ok i sorry i have dylexia so explaing things can be harder than i would like 

    Saturday, July 6, 2019 4:39 PM

All replies

  • Hi elfnliedtopfan2,

    Thank you for posting here.

    For your question, you want to change values on new file according to the file loaded.

    Since the file is not a normal file, I think the best way to solve it is to read his string and replace it.

    You could try the following code.

     string text = File.ReadAllText("D:\\test1.txt");
                int index = text.IndexOf("displayName");
                string m = text.Substring(index + 11, 12).Replace("\\","").Trim();
                string t= File.ReadAllText("D:\\test2.txt");
                index = t.IndexOf("displayName");
                string m1 = t.Substring(index + 11, 12).Replace('"',' ').Trim();
                string result = t.Replace(m1, m);
                File.WriteAllText("D:\\output.gdt", result);


    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 8, 2019 5:47 AM