Jump to content




How to Remove A Portion of a String After a Delimiter


  • You cannot reply to this topic
2 replies to this topic

#1 TehTotalPwnage

  • Members
  • 15 posts

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?

#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

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 by Dog, 21 December 2015 - 08:41 PM.


#3 TehTotalPwnage

  • Members
  • 15 posts

Posted 21 December 2015 - 08:45 PM

View PostDog, on 21 December 2015 - 08:39 PM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users