Remove part of a string?

If I had a string like this, “123456789” what function could I use to remove 6789 from the string?

string.sub or string.gsub

There are several ways it can be done. For strings where you know what you want to remove and it’ll always be the same ( same position ) then you can use string.sub or two and concatenate them together, skipping the last x by using [lua]string.sub( “123456789”, 1, string.len( “123456789” ) - 4 );[/lua]

You can use string.gsub to find / replace things in a string, this can also match patterns by using a %x modifier, where x is the type of characters you want to match and the capitalization of the x is the inverse. http://www.lua.org/pil/20.2.html

[lua]. all characters
%a letters
%c control characters
%d digits
%l lower case letters
%p punctuation characters
%s space characters
%u upper case letters
%w alphanumeric characters
%x hexadecimal digits
%z the character with representation 0[/lua]

so:
[lua]local _string = “123456789”;
print( string.gsub( _string, “6789”, “” ) ); – Replaces the 6789 with nothing
print( string.gsub( string, “%d”, "" ) ); – Replaces all digits with _
print( string.gsub( string, “%D”, "" ) ); – Replaces all NON digits with _[/lua]

Thanks!