Author Topic: How to remove leadin of traling spaces from a string  (Read 2104 times)

0 Members and 1 Guest are viewing this topic.

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
How to remove leadin of traling spaces from a string
« 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

Eyes says everything,
Its on you how u read em...

PtokaX forum

How to remove leadin of traling spaces from a string
« on: 22 April, 2009, 17:28:53 »

Offline HaArD

  • Double Ace
  • *
  • Posts: 104
  • Karma: +2/-1
Re: How to remove leadin of traling spaces from a string
« Reply #1 on: 22 April, 2009, 19:59:39 »
This will actually strip leading and trailing spaces.

Code: [Select]
    function trim (s)
      return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: How to remove leadin of traling spaces from a string
« Reply #2 on: 30 April, 2009, 07:52:12 »
Thanks buddy

Thats great help

Eyes says everything,
Its on you how u read em...

PtokaX forum

Re: How to remove leadin of traling spaces from a string
« Reply #2 on: 30 April, 2009, 07:52:12 »