Remove OSCReceiver message from string

Hi, I am receiving text from OSC and I cannot remove the header from the message? The text I receive looks like this: OSCMessage:“/example/7/” : (OSCValue(String) : “He was the first android I encountered and he proved to be quite durable.”) and basically I only want: He was the first android I encountered and he proved to be quite durable.

I have tried this:

protected void MessageReceived(OSCMessage message)
        { 
             const string quote = "\"";
            string remove = "<OSCMessage:" + quote + "/ example / 7 /" + quote + "> : (OSCValue(String) :";
                string massage = message.ToString();

            Mssg = massage.Replace(remove, "");
     
            AI.text = Mssg;
            Debug.Log(Mssg);
         
        }

This does not remove anything. Does anyone know any other way of removing the text around the message I need? Thank you!

If the OSCMessage is the same length every time, can’t you just use SubString?

1 Like

Thanks for the reply. I am not familiar with SubString but I will look into it. Do you know if that will remove the quotes around the message as well?

Ahh no sorry this will not work because the message inside will be different every time.

What do you mean different every time? Your example uses a static string for the first part of the message, so it would effectively accomplish what it looked like you were trying to do in your post, you would just need to supply it an index, which would be the length of the first part of the message.

If you mean the first part always changes as well, assuming it has a pattern, you can just search for the third quotation and SubString to that, and also SubString the last quotation as well. The link I gave you has examples.

Ahh sorry I am still a bit rusty with my coding. I figured it out now with substring! Thank you!!
I did this:
Mssg = message.ToString();
Mssg = Mssg.Remove(0, 50);
Mssg = Mssg.Substring(0, Mssg.Length - 2);

And if it gets any hairier than this, I think the next thing Rad was about to tell you was to check out Regular Expressions:

https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference

But hey, if .Remove() and .Substring() solves it for you, go with it!!

1 Like