Search code examples
c#stringtextboxstringreader

How to get a certain string from text. C#


So i am trying to make a minecraft launcher but it won't log in to server's because my account is migrated to Mojang so i log in with my email instead of my username but there is a way to get my username so i have found out how but i need to get a string of code from this text using c#.

"134382:deprecated:USERNAME:7a909de0530c310c69c:dba0c48a038a66bb98"

I need to get the "deprecated:USERNAME" into a separate text box, how would i go about doing this, note i am coding in c# and to get the code above i use this code.

http://login.minecraft.net/?user=USERNAME&password=PASSWORD&version=15

this is the code so far

private void PlayBtn_Click(object sender, EventArgs e)
    {
        string username = UsernameBox.Text;
        string password = PasswordBox.Text;
        Process proc = new Process();
        startMinecraft(true, 256, 1024, username, username, false);
    }
    public static void startMinecraft(bool mode, int ramMin, int ramMax, string username, string sessionID, bool debug)
    {
        string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\";
        string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
        Process proc = new Process();
        if (debug == true)
        {
            proc.StartInfo.FileName = "java";
        }
        else
        {
            proc.StartInfo.FileName = "javaw";
        }

        //Online and offline modes
        if (mode == true)
        {
            proc.StartInfo.Arguments = "-Xms" + ramMin + "M -Xmx" + ramMax + "M -Djava.library.path=" + appData + ".minecraft/bin/natives -cp " + appData + ".minecraft/bin/minecraft.jar;" + appData + ".minecraft/bin/jinput.jar;" + appData + ".minecraft/bin/lwjgl.jar;" + appData + ".minecraft/bin/lwjgl_util.jar net.minecraft.client.Minecraft " + username + " " + sessionID;
        }
        else
        {
            proc.StartInfo.Arguments = "-Xms" + ramMin + "M -Xmx" + ramMax + "M -Djava.library.path=" + appData + ".minecraft/bin/natives -cp " + appData + ".minecraft/bin/minecraft.jar;" + appData + ".minecraft/bin/jinput.jar;" + appData + ".minecraft/bin/lwjgl.jar;" + appData + ".minecraft/bin/lwjgl_util.jar net.minecraft.client.Minecraft " + username;
        }
        proc.Start();
    }

Solution

  • if the order remains the same, you can try this

      string[] results = yourstring.split(':');
      yourtextbox.Text = results[1]+ ":" + results[2];   //results1 will give depreciated and results 2 will give UsErname