Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

string_trim

By Daniel · December 25, 2008

Removes whitespace from both sides of a string

// string_trim(str)
// Removes whitespace from both sides of a string

var str, ws_chars;

str = argument0;
ws_chars = chr(9) + chr(10) + chr(13) + chr(32) + '#'; // tab, NL, CR, space, #

// Remove from front
while (string_count(string_char_at(str, 1), ws_chars) > 0)
  str = string_delete(str, 1, 1);

// Remove from back
while (string_count(string_char_at(str, string_length(str)), ws_chars) > 0)
  str = string_delete(str, string_length(str), 1);

return str;

Categories: String handling

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement