PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => HOW-TO's => Topic started by: satya on 22 April, 2009, 17:28:53

Title: How to remove leadin of traling spaces from a string
Post by: satya on 22 April, 2009, 17:28:53
Hi


I want to remove all blank spaces from a string.

for ex: local Abc="              Trial test"

how to remove the leading spaces wich will indeed make the var Abc to hold value "Trial test"

thanks
Title: Re: How to remove leadin of traling spaces from a string
Post by: HaArD on 22 April, 2009, 19:59:39
This will actually strip leading and trailing spaces.

    function trim (s)
      return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end
Title: Re: How to remove leadin of traling spaces from a string
Post by: satya on 30 April, 2009, 07:52:12
Thanks buddy

Thats great help