Created
August 30, 2008 10:06
-
-
Save danlucraft/8102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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