Skip to content

Instantly share code, notes, and snippets.

@danlucraft
Created August 30, 2008 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlucraft/8102 to your computer and use it in GitHub Desktop.
Save danlucraft/8102 to your computer and use it in GitHub Desktop.
// Vala string utility functions
// Started: 30 Aug 08
using GLib;
public class StringHelper {
// Replace all occurences of match_string with replacement_string inside start_string.
// Uses GLib.Regex.replace_literal internally. Returns the empty string if there was
// a RegexError.
public static string gsub(string start_string, string match_string, string replacement_string) {
GLib.Regex grx;
string result;
try {
grx = new GLib.Regex(GLib.Regex.escape_string(match_string));
result = grx.replace_literal(start_string, start_string.size(), 0, replacement_string);
}
catch(GLib.RegexError e) {
return "";
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment