Jump to content
C4 Forums | Control4

driver or some way to manipulate strings?


Recommended Posts

Are there any drivers (or maybe there's some built in functionality that i'm not aware of) to manipulate strings?

Let's say I want to take a variable that contains text like "info1_info2" and I want to separate that string into 2 pieces such that i can separately access "info1" and "info2"?

Thanks,

Steve

Link to comment
Share on other sites


Thanks for the reply.

I'm using the driver RyanE posted in this thread: http://c4forums.com/viewtopic.php?id=12278 (btw, thanks Ryan!)

I'm currently playing around with my cameras and their ability to trigger/call a webpage...so let's say the camera detects motion and I want to lock or unlock a specific door. I could have the cameras send:

http://192.168.1.1:8080/lock_frontdoor

or it could call:

http://192.168.1.1:8080/unlock_reardoor

In theory I could test the one "COMMAND" for all possible permutations, but I was hoping to be able to take the "COMMAND" and break it apart into two variables one that stores whether to lock or unlock and the other to store which door.

This example may not make a lot of practical sense, but i'm just experimenting for now - I can imagine some "COMMAND"s being more complex with more than two variables, etc

Thanks,

Steve

Link to comment
Share on other sites

It's questions like this that make me want to pull apart the software to see what it's doing and how. "Composer" is a nice program and super simple for the uninitiated but it almost seems like a hindrance to someone who knows how to write code. Of course not knowing the inner working of C4 or ComposerPro I may be wrong.

Is it sickness that I'd be willing to work for someone, doing remote programing, for nothing more thpros copy of Pro and really dig into my system and see how its working and how far I can push it. To me figuring out and writing code is better then an xbox or playstation

Link to comment
Share on other sites

  • 4 weeks later...
It's questions like this that make me want to pull apart the software to see what it's doing and how. "Composer" is a nice program and super simple for the uninitiated but it almost seems like a hindrance to someone who knows how to write code. Of course not knowing the inner working of C4 or ComposerPro I may be wrong.

Is it sickness that I'd be willing to work for someone, doing remote programing, for nothing more thpros copy of Pro and really dig into my system and see how its working and how far I can push it. To me figuring out and writing code is better then an xbox or playstation

Nothing stopping you from writing your own composer program. At the end of the day all its doing is outputting XML to Control4 for its project. Just need to shell into your controller and view DirectorState.xml to get an idea of how it all works.

Link to comment
Share on other sites

There's other ways to do it, as you can see here http://stackoverflow.com/questions/1426954/split-string-in-lua but this might be a bit easier to follow:

s = "lock_frontdoor"
splitLocation = string.find(s, "_")
firstHalf = string.sub(s, 0, splitLocation - 1)
secondHalf = string.sub(s, splitLocation + 1)
print("String: " .. s , " splitLocation: " .. splitLocation .. " firstHalf: " .. firstHalf .. " secondHalf: " .. secondHalf)

Link to comment
Share on other sites

It's easier to use Lua patterns. Assuming you will always have one and only one underscore, I'd do it like this:

local _, _, cmd, location = string.find(s, "(.*)_(.*)")

Example:

local s = "lock_frontdoor"

local _, _, cmd, location = string.find(s, "(.*)_(.*)")

print(cmd, location)

prints out: lock frontdoor

RyanE

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.