How do i split() the incoming args?

so if I pass args=1,2,3 what is the best way to split this? in c# I can just call
string[] arg_list = args.Split(",");
but I dont know what to call here, can someone point me in the right direction?

If I cant do something like this:
if(strcmp(args[0], “,”) == 0){}

how am I supposed to figure out what is contained in args?

We use the “String” object, borrowed from Arduino:

This isn’t documented in our own docs, which is an issue that we should fix.

Zach, thanks as always. It is now working!

You should put that into your docs just for completeness, and because I technically know there are a lot of ways to solve that but I wasn’t sure what was possible on the SparkCore.

Just for anyone else who has this issue, this is what I did:

    int commaPosition = args.indexOf(",");
    send_message(args.substring(0,commaPosition));//send first part to line 1
    sendCommand(0xC0);// ** New Line on OLED
    send_message(args.substring(commaPosition+1, args.length()));//send remaining part to line 2
    send_message(args);//send everything to line 1

My case will be different then yours, but what I was trying to do was pass 2 lines of text separated by a comma to an OLED. For example: “first line, second line”

I needed to have the first part (before the comma) be displayed on the first line of the OLED and the second part (after the comma) be displayed on the second line. What I have above does just that.

1 Like