This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TehTotalPwnage's profile picture

How to Remove A Portion of a String After a Delimiter

Started by TehTotalPwnage, 21 December 2015 - 07:24 PM
TehTotalPwnage #1
Posted 21 December 2015 - 08:24 PM
I'm writing a program and I need to process a string so that when a certain character is detected, then the character and the rest of the string after it is removed. For example:

s = somestring/somedelimiter.randomcharacters12345
If I use / as a delimiter, the only thing that should be kept is:

somestring
How would I accomplish this in LUA?
Dog #2
Posted 21 December 2015 - 08:39 PM
I *think* this will do it for you - untested…

local yourString = "somestring/somedelimiter.randomcharacters12345"
local s = yourString:sub(1, yourString:find("/") - 1)
Edited on 21 December 2015 - 07:41 PM
TehTotalPwnage #3
Posted 21 December 2015 - 08:45 PM
I *think* this will do it for you - untested…

local yourString = "somestring/somedelimiter.randomcharacters12345"
local s = yourString:sub(1, yourString:find("/") - 1)
Just tested it on the LUA interactive command line on my system. The code works fine. Thanks!