user3363294
user3363294

Reputation: 47

how to place text inside quotes

I'm trying to add your computer name to the name of the plugin text. Here is a example:

  1. I have a path which detects file which is here:

    string pypath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
    + "\\elfen_encore\\extra_maya\\mayaplugins\\CoDMayaTools.py";
    
  2. From there I use this code to access a string in there

    public void changepy()
    {
         if (File.Exists(pypath))
         {
            {
                string quotes = "\"\"";
                string name =  System.Environment.MachineName;
                string text = File.ReadAllText(pypath);
                text = text.Replace("\"Call of Duty Tools\"", quotes + name);
    
                File.WriteAllText(pypath, text + name);
             }
             MessageBox.Show("Changed  ");
          }
          else
          {
    
          }
    

Then this is the file it should change to computer name :

OBJECT_NAMES =  {'menu'  :      ["CoDMayaToolsMenu",            
  "Call of Duty Tools",     None,                   None,                   None],

"CoDMayaToolsMenu" is the issue; I want to replace that with the users computer name but as you can see its in quotes and I am having huge issues on trying to get the text in the quotes. How can I solve it?

Upvotes: 2

Views: 83

Answers (2)

Dave Jellison
Dave Jellison

Reputation: 933

If you're leaving the quotes anyway, why not this approach? ... It's a bit unclear if this is what you're trying to accomplish?

public void changepy()
{
     if (File.Exists(pypath))
     {
         string machineName = System.Environment.MachineName;
         string content = File.ReadAllText(pypath);
         content = content.Replace("Call of Duty Tools", machineName);

         File.WriteAllText(pypath, content);

         MessageBox.Show("Changed");
     }
     else
     {
     }
}

Upvotes: 0

Hernan Guzman
Hernan Guzman

Reputation: 1235

Is this what you are trying to do?

text = text.Replace("\"Call of Duty Tools\"", "\"" + name + "\"");

If not, please specify a little bit more your question or your desired output.

Upvotes: 2

Related Questions