none
parsing and saving question regarding regex

    Question

  • ok what i want to do is create a regex class wich i have done only issue i have is i not sure if its the best way of doing it so what i want to do is the following 

    the file is in this kind of format. 

    {
    	"zm_p90" ( "bulletweapon.gdf" )
    	{
    		"activate_mode" "hold"
    		"activate_with_primed_delay" "0"
    		"activatesSlam" "0"
    		"activatesSlamAsMelee" "0"
    		"activatesSlamAsPowerMelee" "0"
    		"activatesSlamAsPowerMeleeLeft" "0"
    		"acv_acog" ""
    		"acv_damage" ""
    		"acv_dualclip" ""
    		"acv_dualoptic" ""
    		"acv_dw" ""
    		"acv_dynzoom" ""
    		"acv_extbarrel" ""
    		"acv_extclip" ""
    		"acv_fastads" ""
    		"acv_fastreload" ""
    		"acv_fmj" ""
    		"acv_gl" ""
    		"acv_gmod0" ""
    		"acv_gmod1" ""
    		"acv_gmod2" ""
    		"acv_gmod3" ""
    		"acv_gmod4" ""
    		"acv_gmod5" ""
    		"acv_gmod6" ""
    		"acv_gmod7" ""
    		"acv_grip" ""
    		"acv_holo" ""
    		"acv_ir" ""
    		"acv_is" ""
    		"acv_mk" ""
    		"acv_mms" ""
    		"acv_none" ""
    		"acv_notracer" ""
    		"acv_precision" ""
    		"acv_quickdraw" ""
    		"acv_rangefinder" ""
    		"acv_recon" ""
    		"acv_reddot" ""
    		"acv_reflex" ""
    		"acv_rf" ""
    		"acv_sf" ""
    		"acv_stackfire" ""
    		"acv_stalker" ""
    		"acv_steadyaim" ""
    		"acv_supply" ""
    		"acv_suppressed" ""
    		"acv_swayreduc" ""
    		"acv_tacknife" ""
    		"acv_vzoom" ""
    		"additionalTracesOffset" "0"
    		"adsAdditiveFallScalar" "0.5"
    		"adsAdditiveJumpLandScalar" "0.5"
    		"adsAdditiveJumpScalar" "0.5"
    		"adsAimPitch" "0"
    		"adsAltDropAnim" ""
    		"adsAltDropTime" "0"
    		"adsAltRaiseAnim" ""
    		"adsAltRaiseTime" "0"
    		"adsBobFactor" "0"
    		"adsCrosshairInFrac" "0.5"
    		"adsCrosshairOutFrac" "0.2"
    		"adsDofEnd" "7.5"
    		"adsDofStart" "0"
    		"adsDownAnim" "jzob_kf2_p90_ads_down"
    		"adsFire" "0"
    		"adsFireAnim" "jzob_kf2_p90_ads_fire"
    		"adsFireDelayAnim" ""
    		"adsFireIntroAnim" ""
    		"adsFiringFlinchScalar" "0.55"
    		"adsFiringSpeedScale" "0"
    		"adsFlinchScalar" "0.55"
    		"adsGunKickAccel" "700"
    		"adsGunKickPitchMax" "15"
    		"adsGunKickPitchMin" "5"
    		"adsGunKickReducedKickBullets" "0"
    		"adsGunKickReducedKickPercent" "75"
    		"adsGunKickSpeedDecay" "35"
    		"adsGunKickSpeedMax" "2000"
    		"adsGunKickStaticDecay" "10"
    		"adsGunKickYawMax" "10"
    		"adsGunKickYawMin" "-5"
    		"adsIdleAmount" "30"
    		"adsIdleSpeed" "1.5"
    		"adsLastShotAnim" "jzob_kf2_p90_ads_fire"
    		"adsLowerSoundPlayer" "fly_generic_ads_lower_plr"
    		"adsMoveSpeedScale" "2"
    		"adsMoveSpeedTransitionTimeIn" "0.2"
    		"adsMoveSpeedTransitionTimeOut" "0"
    		"adsOnly" "0"
    		"adsOverlayAlphaScale" "1"
    		"adsOverlayHeight" "220"
    		"adsOverlayReticle" "none"
    		"adsOverlayShader" ""
    		"adsOverlayShaderLowRes" ""
    		"adsOverlayWidth" "220"
    		"adsProneMove" "0"
    		"adsRaiseSoundPlayer" "fly_generic_ads_plr"
    		"adsRechamberAnim" ""
    		"adsRecoilReductionLimit" "0"
    		"adsRecoilReductionRate" "0"
    		"adsRecoilReturnRate" "1"
    		"adsReloadTransTime" "0.175"
    		"adsScopeBlurAmount" "0"
    		"adsScopeBlurRadius" "0"
    		"adsScopeBlurStart" "0"
    		"adsSpread" "0.4"
    		"adsSwayHorizScale" "0.25"
    		"adsSwayLerpSpeed" "6"
    		"adsSwayMaxAngle" "4"
    		"adsSwayPitchScale" "0.1"
    		"adsSwayTransitionLerpSpeed" "20"
    		"adsSwayVertScale" "0.25"
    		"adsSwayViewInsteadOfGun" "0"
    		"adsSwayYawScale" "0.1"
    		"adsTransBlendTime" "0.1"
    		"adsTransInTime" "0.25"
    		"adsTransOutTime" "0.25"
    		"adsTurnRateScalar" "1"
    		"adsUpAnim" "jzob_kf2_p90_ads_up"
    		"adsUpOtherScopeAnim" ""
    		"adsViewBobMult" "0.25"
    		"adsViewErrorMax" "0"
    		"adsViewErrorMin" "0"
    		"adsViewKickCenterDuckedScale" "1"
    		"adsViewKickCenterProneScale" "1"
    		"adsViewKickCenterSpeed" "1700"
    		"adsViewKickMinMagnitude" "10"

    i want to find the the key witch for this example i say is "Activemode" < and i want to display the value witch would be > "hold"

    but the issue i am having is i cant use dictunary due to the fact there are multible occorances of the value 

    so i thought going though and trying to get regex to find the key and value via group might work but not sure how i would implment it so what i want to achive 

    is have key witch is on the left and value to be the right and display value only in a text box and the user can make changes and hit save and it only edit the value and save back but not sure how to get this to work without dictunary 

    this code not currently working but what i have tryied to do

            // this is where we going to get patterns
    
            public static string pattern = "[a-zA-Z+]/s [a-zA-Z0-9+] ";
            public string TAToolsPath = Environment.GetEnvironmentVariable("TA_TOOLS_PATH");
    
    
    
            public void readfile()
            {
    
                Regex regex = new Regex(pattern);
    
                using (StreamReader reader = new StreamReader(TAToolsPath + @"share\raw\behavior\zm_factory_zombie_dog.ai_bt"))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // Try to match each line against the Regex.
                        Match match = regex.Match(line);
                        if (match.Success)
                        {
                            // Write original line and the value.
                            string v = match.Groups[1].Value;
                            MessageBox.Show(line);
                            MessageBox.Show("..." + v);
                           // Console.WriteLine(line);
                        }
                    }
                }
             
            }

    thanks in advance elfenliedtopfan5 


    Sunday, December 30, 2018 8:19 PM

All replies

  • Hi elfenliedtopfan2,

    Thank you for posting here.

    For your question, you could create your own Dictionary with key and value. Please try the code below.

     class Dic
        {
            public string Key { get; set; }
            public string Value { get; set; }
        }
        class Program
        {
            static void Main(string[] args)
            {            
                List<Dic> list = new List<Dic>();
                var lines = File.ReadAllLines("3.txt");
                
                foreach (var line in lines)
                {
                    MatchCollection match = Regex.Matches(line, "\\\"(.*?)\\\"");
                    if (match.Count == 2)
                    {
                        Dic dic = new Dic
                        {
                            Key = match[0].Value,
                            Value = match[1].Value
                        };
                        list.Add(dic);
                    }
    
                }
    
                Console.ReadKey();
    
            }

    Best Regards,

    Wendy


    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, December 31, 2018 2:49 AM
    Moderator
  • Hi elfenliedtopfan2,

    Thank you for posting here.

    For your question, you could create your own Dictionary with key and value. Please try the code below.

     class Dic
        {
            public string Key { get; set; }
            public string Value { get; set; }
        }
        class Program
        {
            static void Main(string[] args)
            {            
                List<Dic> list = new List<Dic>();
                var lines = File.ReadAllLines("3.txt");
                
                foreach (var line in lines)
                {
                    MatchCollection match = Regex.Matches(line, "\\\"(.*?)\\\"");
                    if (match.Count == 2)
                    {
                        Dic dic = new Dic
                        {
                            Key = match[0].Value,
                            Value = match[1].Value
                        };
                        list.Add(dic);
                    }
    
                }
    
                Console.ReadKey();
    
            }

    Best Regards,

    Wendy


    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.

    that is amazing thank you so much only cople of things how can i display like say active mode how can i get it to display the value to text box and save the edit i know i can do something like 

    textbox1.text = key.value or something like that just not sure how to access and save back to the file. 

    thanks for your reply. 

    Tuesday, January 1, 2019 1:20 AM
  • Hi elfenliedtopfan2,

    Thank you for feedback.

    For your question, if you want to show the value in TextBox and save the edit, I suggest you do not use regex. The data you provided seems like a json file. You could analyze the json file and show it in TexBox and save the edit.

    Without the completed data, I use a simple json data for reference.

    My original json data.

    Here is my code.

      static string json = File.ReadAllText("2.txt");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);
            private void btnLoad_Click(object sender, EventArgs e)
            {
                textBox1.Text = jsonObj["Name"];
            }
    
            private void btnSave_Click(object sender, EventArgs e)
            {
                jsonObj["Name"] = textBox1.Text;
                string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                File.WriteAllText("2.txt", output);
            }

    My results.

    Best Regards,

    Wendy


    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.

    Tuesday, January 1, 2019 7:13 AM
    Moderator
  • i get the following error 

    An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll

    Additional information: Invalid character after parsing property name. Expected ':' but got: (. Path '', line 2, position 10.

    wich i assume as json requires : and the file in question is seprated by whitespace could be the reason 

    this is the whole file

    wholefile

    Tuesday, January 1, 2019 10:23 PM
  • "but the issue i am having is i cant use dictionary due to the fact there are multiple occurrences of the value"

    Hi Elfen.

    I seem to recall that it doesn't matter if there are multiple instances of a value. It's the key which must be unique.

    I just wrote a little routine to read a portion of the file you submitted. Then I inserted two entries of my own so that the first three entries are …

            string[] zpzm_p90 =
        {
            "activate_mode\" \"hold",
            "reactivate_mode\" \"hold",
            "deactivate_mode\" \"hold",
    

    They seem to be entered into the dictionary without incident.

            Match KeyValues;
            string fileRGX = @"(?<key>[\w_-]+)[^\w]+(?<value>[\w_-]+)";
            Dictionary<string, string> fileData = new Dictionary<string, string>();
    
    
    
    
                string key, value, Q60;
                for (int i = 0; i < 3; i++)
                {
                    Q60 = zpzm_p90[i];
                    KeyValues = (new Regex(fileRGX)).Match(Q60);
                    key = KeyValues.Groups["key"].Value;
                    value = KeyValues.Groups["value"].Value;
                    fileData.Add(key, value);
                }
    

    Tuesday, January 1, 2019 11:05 PM
  • "but the issue i am having is i cant use dictionary due to the fact there are multiple occurrences of the value"

    Hi Elfen.

    I seem to recall that it doesn't matter if there are multiple instances of a value. It's the key which must be unique.

    I just wrote a little routine to read a portion of the file you submitted. Then I inserted two entries of my own so that the first three entries are …

            string[] zpzm_p90 =
        {
            "activate_mode\" \"hold",
            "reactivate_mode\" \"hold",
            "deactivate_mode\" \"hold",

    They seem to be entered into the dictionary without incident.

            Match KeyValues;
            string fileRGX = @"(?<key>[\w_-]+)[^\w]+(?<value>[\w_-]+)";
            Dictionary<string, string> fileData = new Dictionary<string, string>();
    
    
    
    
                string key, value, Q60;
                for (int i = 0; i < 3; i++)
                {
                    Q60 = zpzm_p90[i];
                    KeyValues = (new Regex(fileRGX)).Match(Q60);
                    key = KeyValues.Groups["key"].Value;
                    value = KeyValues.Groups["value"].Value;
                    fileData.Add(key, value);
                }

    ok it somewhat seems to work i get same key occerance but its the very top bit i think like 

    "zm_p90" ( "bulletweapon.gdf" )

    that gives 2 occerances of the same key i think so need to find a way of starting at a certin point and how can i display a value of a key to a textbox

    Wednesday, January 2, 2019 1:03 AM
  • i get this error as well and have no idea why 
    Wednesday, January 2, 2019 1:15 AM
  • Hello again, Elfin.

    My earlier comments were in response to your statement that you couldn't use a Dictionary because you had multiple instances of a single value. but you seem to be encountering multiple instances of a key. That is, regrettably, a problem to be addressed.   If you decide to use a Dictionary, then you must change your strategy...

    What I would do, and will do later this evening, is to preface the .Add(new_key, new_value) with a .ContainsKey(new_key). If 'ContainsKey' returns 'false' then perform the .Add as shown, and go on to the next iteration.

    But, if it returns 'true', then execute a 'TryGetValue(new_key)' which returns the existing value. Then append 'new_value' to the existing value (separated by comma or other separator of your choosing) and place that in 'new_value'.

    Then issue a .Remove(new_key) followed by .Add(new_key, new_value').

    The strategy is that if the key is NOT already in the dictionary, then it's business as usual … add the new key and value, and go on to the next iteration.

    BUT, if the key already exists in the dictionary, then we must append 'new_value" to the existing value (assuming that both new_value and the existing value are NOT identical).   Of course, if the existing value and 'new_value' ARE identical, that's a freebie - do nothing; go on to the next iteration.

    The screen shot you posted appears to be informing you that you attempted to enter a key which already exists in the dictionary. I would expect that the strategy we just discussed will prevent that.

    HINT: The Microsoft Docs 'Help' is exemplary. 

    Or google something like "C# Dictionary(Tkey,"



    • Edited by Lincoln_MA Wednesday, January 2, 2019 3:38 AM
    Wednesday, January 2, 2019 3:32 AM
  • Hi elfenliedtopfan2,

    The file you provided is not a correct json format. I make a combobox to show the key and then save changed value in file.

    Here is the code.

    using Spire.Xls;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;
    using System.ComponentModel;
    using System.Windows.Media;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Text.RegularExpressions;
    using Newtonsoft.Json;
    
    namespace WindowsForms
    {
    
        public partial class Test : Form
        {
    
            public Test()
            {
                InitializeComponent();
    
            }
            List<Dic> list = new List<Dic>();
            private void Test_Load(object sender, EventArgs e)
            {
    
                var lines = File.ReadAllLines("4.txt");
    
                foreach (var line in lines)
                {
                    MatchCollection match = Regex.Matches(line, "\\\"(.*?)\\\"");
                    if (match.Count == 2)
                    {
                        Dic dic = new Dic
                        {
                            Key = match[0].Value,
                            Value = match[1].Value
                        };
                        list.Add(dic);
                    }
    
                }
                foreach (var item in list)
                {
                    comboBox1.Items.Add(item.Key);
                }
            }
            class Dic
            {
                public string Key { get; set; }
                public string Value { get; set; }
            }
           
            private void btnLoad_Click(object sender, EventArgs e)
            {
                var key = comboBox1.SelectedItem.ToString();
                foreach (var item in list)
                {
                    if (item.Key == key)
                    {
                        textBox1.Text = item.Value;
                    }
                }
            }
    
            private void btnSave_Click(object sender, EventArgs e)
            {
                var key = comboBox1.SelectedItem.ToString();
                string text = File.ReadAllText("4.txt");
                string value=string.Empty;
                foreach (var item in list)
                {
                    if (item.Key == key)
                    {
                        value = item.Value;
                    }
                }
                text = text.Replace(value, textBox1.Text);
                File.WriteAllText("4.txt", text);
            }
        }
    }
    
    
    
    

    Best Regards,

    Wendy


    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.

    Wednesday, January 2, 2019 6:39 AM
    Moderator
  • Hi elfenliedtopfan2,

    The file you provided is not a correct json format. I make a combobox to show the key and then save changed value in file.

    Here is the code.

    using Spire.Xls;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;
    using System.ComponentModel;
    using System.Windows.Media;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Text.RegularExpressions;
    using Newtonsoft.Json;
    
    namespace WindowsForms
    {
    
        public partial class Test : Form
        {
    
            public Test()
            {
                InitializeComponent();
    
            }
            List<Dic> list = new List<Dic>();
            private void Test_Load(object sender, EventArgs e)
            {
    
                var lines = File.ReadAllLines("4.txt");
    
                foreach (var line in lines)
                {
                    MatchCollection match = Regex.Matches(line, "\\\"(.*?)\\\"");
                    if (match.Count == 2)
                    {
                        Dic dic = new Dic
                        {
                            Key = match[0].Value,
                            Value = match[1].Value
                        };
                        list.Add(dic);
                    }
    
                }
                foreach (var item in list)
                {
                    comboBox1.Items.Add(item.Key);
                }
            }
            class Dic
            {
                public string Key { get; set; }
                public string Value { get; set; }
            }
           
            private void btnLoad_Click(object sender, EventArgs e)
            {
                var key = comboBox1.SelectedItem.ToString();
                foreach (var item in list)
                {
                    if (item.Key == key)
                    {
                        textBox1.Text = item.Value;
                    }
                }
            }
    
            private void btnSave_Click(object sender, EventArgs e)
            {
                var key = comboBox1.SelectedItem.ToString();
                string text = File.ReadAllText("4.txt");
                string value=string.Empty;
                foreach (var item in list)
                {
                    if (item.Key == key)
                    {
                        value = item.Value;
                    }
                }
                text = text.Replace(value, textBox1.Text);
                File.WriteAllText("4.txt", text);
            }
        }
    }
    
    
    

    Best Regards,

    Wendy


    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.

    omg that works pefectly only question i have now is is there a way to manually edit the value like say i wanted to access 

    weaponname on save and change it manually as it saves is that possible ?
    Thursday, January 3, 2019 12:27 AM
  • Hi elfenliedtopfan2,

    Thank you for feedback.

    According to my code, you could choose the key in ComboBox and then click Load Button to load the value in TextBox. You could change the value in TextBox and then click Save button to save the value in the file like what I showed in the gif in my previous reply.

    But the weaponname could not find in the data you provided.

    Best Regards,

    Wendy


    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.


    Thursday, January 3, 2019 5:44 AM
    Moderator
  • Hi elfenliedtopfan2,

    Thank you for feedback.

    According to my code, you could choose the key in ComboBox and then click Load Button to load the value in TextBox. You could change the value in TextBox and then click Save button to save the value in the file like what I showed in the gif in my previous reply.

    But the weaponname could not find in the data you provided.

    Best Regards,

    Wendy


    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.


    Yeah that works perfectly but say i wanted to change only a cople manually like say 

    "emptyDropAnim" "....."

    how can i load that passific key and change the value its just for somehing i a planning but i need to be able to change the value manually like via code insted of textbox the rest i do its just a copule where i would like to change via code.

    Thursday, January 3, 2019 2:59 PM
  • Hi elfenliedtopfan2,

    >>the rest i do its just a copule where i would like to change via code.

    Sorry for that, I do not understand what you want according to your feedback.

    Please provide more details. It would be better to tell us what you want to change and what is the result you want.

    Best Regards,

    Wendy


    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, January 7, 2019 6:49 AM
    Moderator
  • Hi elfenliedtopfan2,

    >>the rest i do its just a copule where i would like to change via code.

    Sorry for that, I do not understand what you want according to your feedback.

    Please provide more details. It would be better to tell us what you want to change and what is the result you want.

    Best Regards,

    Wendy


    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.

    what i mean the loading into combo box and selecting key and loading value is great but i also need to revrence them via code so i can manually add a key in so something like 

    Dic dic = new dic()
    {
      key["sprintLoopAnim"] = "ballista_sprint_loop";
    }

    but only when i select save because what im going to do is load the file have 4 diffent classes 

    smg

    ar

    rifle

    sniper 

    and what one is slected i want to auto fill certin parts of the keys and values like ammo and all the weapon animation fileds ect 

    and have the rest in a combo box to edit if that makes little more sense im sorry i have dyslixa so have trouble explaining well.


    Tuesday, January 8, 2019 2:05 PM
  • Hi elfenliedtopfan2,

    Sorry for that. The class Dic is defined by myself, it could not be used like Dictionary in the code below.

    Dic dic = new dic()
    {
      key["sprintLoopAnim"] = "ballista_sprint_loop";
    }

    Your data is not the correct format of json. Hence the way I provided in the previous reply is not suitable as well.

    Best Regards,

    Wendy


    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.

    Thursday, January 10, 2019 8:48 AM
    Moderator
  • Hello again, Elfin.

    Perhaps you might reconsider your original thought regarding using a conventional .NET Dictionary and a Regex to acquire the data from the file. I proposed that a few days ago and I'm back again to show how it might be accomplished.

    But first, here are my 'Weasel Words':  

    1. It is VERY LIKELY, indeed almost certain, that you'll need to adjust the Regex Pattern. Obviously, I do not have  access to the file you're using, so I had to simulate it. I created it as one long string because that is the most convenient way for me … and that is the method most of the instruments I monitor use in issuing their reports.  However, I think 'tweaking' the Regex should be relatively painless …. I believe that it's basically there.

    2. For my convenience, in addition to the two textboxes you refer to, I added a ListView in order to display the Dictionary contents. Makes debugging a little easier 'cuz you can see the changes.

    3. The source code is contained in two files in my app: Elfen.cs and Form1.cs. Again, that's for MY convenience. I wanted everything in one file for easy posting, but in my app, much of the work is done in the Form1 constructor. I didn't want to take the time to change that.   SO, in Elfen.cs, you'll see code that is commented out. That is not throw-away code,  but in my app, it resides elsewhere (Form1.cs)

    4. This is by no means a finished product.  I have done virtually zip, zero, nada, NO testing … just the most fundamental check to see that the desired changes are made to both the Dictionary and the Listview. It does that.

    OK, so here's Elfen.cs …

    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1
        {
    
            MatchCollection KeyValues;
            string fileRGX = "\"(?<key>[\\w_-]+)\"[\\s(]+\"(?<value>[\\.\\w_-]*)\"";
            Dictionary<string, string> fileData = new Dictionary<string, string>();
    
    
            /*
                    // does he use    "\"zm_p90\" ( "bulletweapon.gdf\" )"  ?      
                    // I have retained it as part of the string, and add
                    // it to the dictionary.
                    zp_Whatever =
                        "\"zm_p90\" ( \"bulletweapon.gdf\" )" +
                        "{" +
                            "\"activate_mode\" \"hold\"" +
                            "\"activate_with_primed_delay\" \"0\"" +
                            "\"activatesSlam\" \"0\"" +
                            "\"activatesSlamAsMelee\" \"0\"" +
                            "\"activatesSlamAsPowerMelee\" \"0\"" +
                            "\"activatesSlamAsPowerMeleeLeft\" \"0\"" +
                            "\"acv_acog\" \"\"" +
                            "\"acv_damage\" \"\"" +
                            "\"acv_dualclip\" \"\"" +
                            "\"acv_dualoptic\" \"\"" +
                            "\"acv_dw\" \"\"" +
                            "\"acv_dynzoom\" \"\"" +
                            "\"acv_extbarrel\" \"\"" +
                            "\"acv_extclip\" \"\"" +
                            "\"acv_fastads\" \"\"" +
                            "\"acv_fastreload\" \"\"" +
                            "\"acv_fmj\" \"\"" +
                            "\"acv_gl\" \"\"" +
                            "\"acv_gmod0\" \"\"" +
                            "\"acv_gmod1\" \"\"" +
                            "\"acv_gmod2\" \"\"" +
                            "\"acv_gmod3\" \"\"" +
                            "\"acv_gmod4\" \"\"" +
                            "\"acv_gmod5\" \"\"" +
                            "\"acv_gmod6\" \"\"" +
                            "\"acv_gmod7\" \"\"" +
                            "\"acv_grip\" \"\"" +
                            "\"acv_holo\" \"\"" +
                            "\"acv_ir\" \"\"" +
                            "\"acv_is\" \"\"" +
                            "\"acv_mk\" \"\"" +
                            "\"acv_mms\" \"\"" +
                            "\"acv_none\" \"\"" +
                            "\"acv_notracer\" \"\"" +
                            "\"acv_precision\" \"\"" +
                            "\"acv_quickdraw\" \"\"" +
                            "\"acv_rangefinder\" \"\"" +
                            "\"acv_recon\" \"\"" +
                            "\"acv_reddot\" \"\"" +
                            "\"acv_reflex\" \"\"" +
                            "\"acv_rf\" \"\"" +
                            "\"acv_sf\" \"\"" +
                            "\"acv_stackfire\" \"\"" +
                            "\"acv_stalker\" \"\"" +
                            "\"acv_steadyaim\" \"\"" +
                            "\"acv_supply\" \"\"" +
                            "\"acv_suppressed\" \"\"" +
                            "\"acv_swayreduc\" \"\"" +
                            "\"acv_tacknife\" \"\"" +
                            "\"acv_vzoom\" \"\"" +
                            "\"additionalTracesOffset\" \"0\"" +
                            "\"adsAdditiveFallScalar\" \"0.5\"" +
                            "\"adsAdditiveJumpLandScalar\" \"0.5\"" +
                            "\"adsAdditiveJumpScalar\" \"0.5\"" +
                            "\"adsAimPitch\" \"0\"" +
                            "\"adsAltDropAnim\" \"\"" +
                            "\"adsAltDropTime\" \"0\"" +
                            "\"adsAltRaiseAnim\" \"\"" +
                            "\"adsAltRaiseTime\" \"0\"" +
                            "\"adsBobFactor\" \"0\"" +
                            "\"adsCrosshairInFrac\" \"0.5\"" +
                            "\"adsCrosshairOutFrac\" \"0.2\"" +
                            "\"adsDofEnd\" \"7.5\"" +
                            "\"adsDofStart\" \"0\"" +
                            "\"adsDownAnim\" \"jzob_kf2_p90_ads_down\"" +
                            "\"adsFire\" \"0\"" +
                            "\"adsFireAnim\" \"jzob_kf2_p90_ads_fire\"" +
                            "\"adsFireDelayAnim\" \"\"" +
                            "\"adsFireIntroAnim\" \"\"" +
                            "\"adsFiringFlinchScalar\" \"0.55\"" +
                            "\"adsFiringSpeedScale\" \"0\"" +
                            "\"adsFlinchScalar\" \"0.55\"" +
                            "\"adsGunKickAccel\" \"700\"" +
                            "\"adsGunKickPitchMax\" \"15\"" +
                            "\"adsGunKickPitchMin\" \"5\"" +
                            "\"adsGunKickReducedKickBullets\" \"0\"" +
                            "\"adsGunKickReducedKickPercent\" \"75\"" +
                            "\"adsGunKickSpeedDecay\" \"35\"" +
                            "\"adsGunKickSpeedMax\" \"2000\"" +
                            "\"adsGunKickStaticDecay\" \"10\"" +
                            "\"adsGunKickYawMax\" \"10\"" +
                            "\"adsGunKickYawMin\" \"-5\"" +
                            "\"adsIdleAmount\" \"30\"" +
                            "\"adsIdleSpeed\" \"1.5\"" +
                            "\"adsLastShotAnim\" \"jzob_kf2_p90_ads_fire\"" +
                            "\"adsLowerSoundPlayer\" \"fly_generic_ads_lower_plr\"" +
                            "\"adsMoveSpeedScale\" \"2\"" +
                            "\"adsMoveSpeedTransitionTimeIn\" \"0.2\"" +
                            "\"adsMoveSpeedTransitionTimeOut\" \"0\"" +
                            "\"adsOnly\" \"0\"" +
                            "\"adsOverlayAlphaScale\" \"1\"" +
                            "\"adsOverlayHeight\" \"220\"" +
                            "\"adsOverlayReticle\" \"none\"" +
                            "\"adsOverlayShader\" \"\"" +
                            "\"adsOverlayShaderLowRes\" \"\"" +
                            "\"adsOverlayWidth\" \"220\"" +
                            "\"adsProneMove\" \"0\"" +
                            "\"adsRaiseSoundPlayer\" \"fly_generic_ads_plr\"" +
                            "\"adsRechamberAnim\" \"\"" +
                            "\"adsRecoilReductionLimit\" \"0\"" +
                            "\"adsRecoilReductionRate\" \"0\"" +
                            "\"adsRecoilReturnRate\" \"1\"" +
                            "\"adsReloadTransTime\" \"0.175\"" +
                            "\"adsScopeBlurAmount\" \"0\"" +
                            "\"adsScopeBlurRadius\" \"0\"" +
                            "\"adsScopeBlurStart\" \"0\"" +
                            "\"adsSpread\" \"0.4\"" +
                            "\"adsSwayHorizScale\" \"0.25\"" +
                            "\"adsSwayLerpSpeed\" \"6\"" +
                            "\"adsSwayMaxAngle\" \"4\"" +
                            "\"adsSwayPitchScale\" \"0.1\"" +
                            "\"adsSwayTransitionLerpSpeed\" \"20\"" +
                            "\"adsSwayVertScale\" \"0.25\"" +
                            "\"adsSwayViewInsteadOfGun\" \"0\"" +
                            "\"adsSwayYawScale\" \"0.1\"" +
                            "\"adsTransBlendTime\" \"0.1\"" +
                            "\"adsTransInTime\" \"0.25\"" +
                            "\"adsTransOutTime\" \"0.25\"" +
                            "\"adsTurnRateScalar\" \"1\"" +
                            "\"adsUpAnim\" \"jzob_kf2_p90_ads_up\"" +
                            "\"adsUpOtherScopeAnim\" \"\"" +
                            "\"adsViewBobMult\" \"0.25\"" +
                            "\"adsViewErrorMax\" \"0\"" +
                            "\"adsViewErrorMin\" \"0\"" +
                            "\"adsViewKickCenterDuckedScale\" \"1\"" +
                            "\"adsViewKickCenterProneScale\" \"1\"" +
                            "\"adsViewKickCenterSpeed\" \"1700\"" +
                            "\"adsViewKickMinMagnitude\" \"10\"" +
                        "}";
            */
    
    
    
    
            //string key, value;
            //string Q60RS;
    
            //Q60RS = zp_Whatever;
            //    KeyValues = (new Regex(fileRGX)).Matches(Q60RS);
            //initializeDictionary(fileData, KeyValues);
    
    
    
    
            // *************************************************************************************
            public void initializeDictionary(Dictionary<string, string> x, MatchCollection items) {
    
                x.Clear();
                foreach (Match match in items) 
                    x.Add(match.Groups["key"].Value, match.Groups["value"].Value);
            }
            // *************************************************************************************
    
    
            // *************************************************************************************
            public void UpdateDictionary(Dictionary<string, string> x, string key, string value) {
    
                if (x.ContainsKey(key))
                    x.Remove(key);
    
                x.Add(key, value);
            }
            // *************************************************************************************
    
    
    
            // *************************************************************************************
            public void InitializeListView(ListView x, MatchCollection items) {
                int i = 0;
                string[] subs = new string[3];
    
                x.Items.Clear();
                foreach (Match match in items) {
                    subs[0] = (++i).ToString();
                    subs[1] = match.Groups["key"].Value;
                    subs[2] = match.Groups["value"].Value;
    
                    x.Items.Add(new ListViewItem(subs));
                }
                x.Show();
            }
            // *************************************************************************************
    
            // *************************************************************************************
            public void UpdateListView(string key, string newValue) {
                ListViewItem updatedItem = listView1.FindItemWithText(key);
                updatedItem.SubItems[2].Text = newValue;
            }
            // *************************************************************************************
    
            // *************************************************************************************
            private void listView1_MouseUp(object sender, MouseEventArgs e)
            {
                textBox1.Text = ((ListView)sender).SelectedItems[0].SubItems[1].Text;
                textBox2.Text = ((ListView)sender).SelectedItems[0].SubItems[2].Text;
            }
            // *************************************************************************************
    
            // *************************************************************************************
            private void button1_Click(object sender, EventArgs e)
            {
                string key = textBox1.Text;
                string value = textBox2.Text;
                UpdateListView(key, value);
                UpdateDictionary(fileData, key, value);
                listView1.Show();
            }
            // *************************************************************************************
        }// end this segment, class 'Form1'
    }// end this segment of namespace 'WindowsFormsApp1'

    Again, this is NOT a finished product, you WILL have to tweak it, but it may be a useful example, if nothing else.   Works on my 'chine.


    • Edited by Lincoln_MA Saturday, January 12, 2019 1:25 AM
    Saturday, January 12, 2019 1:21 AM
  • Not to belabor the point,  B  U  T,  as I was reviewing the code a bug leapt up off the screen and crawled across my desk …

    In function 'UpdateListView', I believe there is a problem with the call to ListView function 'FindItemWithText'. As is, it permits partial matches. Thus, the order that an item appears in (ultimately, the ordering of the source string read in) determines whether or not the list will be updated correctly.

    For instance, in the source string created in elfin.cs, if the ordering of the source string was changed such that  "\"activatesSlam\" \"0\"" was moved from its current position to, instead, immediately follow ''"\"activatesSlamAsPowerMeleeLeft\" \"0\"", and then an attempt was made to change the value associated with "\"activatesSlam\" \"0\"", the update would be made incorrectly.  SO, as Is, ordering of the source input string is important (reason being that the underlying function does not check for a match, it checks only to see if an item STARTSWITH the key supplied by caller).

    I propose that two new bools are defined and supplied at arguments to the same function, as in ….

            public const Boolean includeSubItems = true;
            public const Boolean avoidPartialMatch = false;
    
    
    
    and the function call is changed to :
    
               ListViewItem updatedItem = listView1.FindItemWithText(key, includeSubItems, 0, avoidPartialMatch);
    

    Not that anyone cares … this post has been on the board so long that certainly by now, Elfin found a way around the problem and is now nearing retirement.   Still, I wanted to report the bug that leapt off the screen at me.

     

    Saturday, January 12, 2019 10:21 PM
  • Not to belabor the point,  B  U  T,  as I was reviewing the code a bug leapt up off the screen and crawled across my desk …

    In function 'UpdateListView', I believe there is a problem with the call to ListView function 'FindItemWithText'. As is, it permits partial matches. Thus, the order that an item appears in (ultimately, the ordering of the source string read in) determines whether or not the list will be updated correctly.

    For instance, in the source string created in elfin.cs, if the ordering of the source string was changed such that  "\"activatesSlam\" \"0\"" was moved from its current position to, instead, immediately follow ''"\"activatesSlamAsPowerMeleeLeft\" \"0\"", and then an attempt was made to change the value associated with "\"activatesSlam\" \"0\"", the update would be made incorrectly.  SO, as Is, ordering of the source input string is important (reason being that the underlying function does not check for a match, it checks only to see if an item STARTSWITH the key supplied by caller).

    I propose that two new bools are defined and supplied at arguments to the same function, as in ….

            public const Boolean includeSubItems = true;
            public const Boolean avoidPartialMatch = false;
    
    
    
    and the function call is changed to :
    
               ListViewItem updatedItem = listView1.FindItemWithText(key, includeSubItems, 0, avoidPartialMatch);

    Not that anyone cares … this post has been on the board so long that certainly by now, Elfin found a way around the problem and is now nearing retirement.   Still, I wanted to report the bug that leapt off the screen at me.

     

    Well no i habe not fixed it i been away on holliday and only just got back 3 days ago so just getting back into things but one thing i will say is the files that i need to parse that is liek a small copy of the file and each one is slightly diffent the weapn side is the same but textures and that are not 

    if you have discord or something along those lines or i can send you a full copy if the file i can go over it in better detail with you its hard to expalain in many words hpefully your still up for helping sorry for such a late reply 

    elfenliedtopfan5

    Monday, January 28, 2019 8:16 AM
  • Hello again Elfin.

    Send a sample file to TerryvilleCT@yahoo.com.  I can't work on it every day … but I can probably find some time at least 3 days per week.    Hopefully we can get this thing rolling rather quickly. I think we're probably pretty close (depending upon the difference between an actual file and the sample you posted here).

    Monday, January 28, 2019 10:45 PM
  • Hello again Elfin.

    Send a sample file to TerryvilleCT@yahoo.com.  I can't work on it every day … but I can probably find some time at least 3 days per week.    Hopefully we can get this thing rolling rather quickly. I think we're probably pretty close (depending upon the difference between an actual file and the sample you posted here).

    I have send email to address provided above i seprated the files so its eaisier to look at but those are the files weapon file is the one currently there and images file in real workflow example those files would be together 
    Thursday, January 31, 2019 5:14 PM
  • Hello Elfin

    I am embarrassed to report that I did not receive your files, and what's worse, I can't send a message to TerryvilleCT@Yahoo.com  either. Clearly, the fault is on my end, not yours.  It was working just last week, but something's happened  'twixt then and now.

    I am eager to look at these files (I love RegEx problems). If you'll give me one more chance to help, you can send the files once again, but this time send'em to PDP_1135@Yahoo.com. I just set that up earlier t'day to get around the problem with the other email address. PDP_1135@Yahoo.com is known to be working (as of this afternoon).

    Sorry 'bout that … I can't explain the problem but I'll look into it and try to resolve it. In the meantime, we can use PDP_1135 to get the ball rolling.

    Friday, February 1, 2019 1:29 AM
  • Got-em !

    They're large!  I'll begin looking at'em this afternoon.

    Thank You.

    Friday, February 1, 2019 5:40 PM