Next: 8.4 Variable number of Up: 8 Some Examples Previous: 8.2 The Functions next

8.3 Manipulating Strings

The first example is a function to trim extra white-spaces at the beginning and end of a string.

function trim(s)
  local _, i = strfind(s, '^ *')
  local f, __ = strfind(s, ' *$')
  return strsub(s, i+1, f-1)
end

The second example shows a function that eliminates all spaces of a string.

function remove_blanks (s)
  return gsub(s, "%s%s*", "")
end


Next: 8.4 Variable number of Up: 8 Some Examples Previous: 8.2 The Functions next