diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index e80f2c4..9b1c1fd 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -32,6 +32,39 @@ return Convert.ToBase64String(value.GetBytes()); } + /// + /// Converts this string from one encoding to another. + /// + /// The input string. + /// The input encoding. + /// The output encoding. + /// Returns a new with its data converted to + /// . + /// is + /// - or - + /// is + /// -or + /// is . + public static string ChangeEncoding(this string str, Encoding from, Encoding to) + { + if (str is null) + { + throw new ArgumentNullException(nameof(str)); + } + + if (from is null) + { + throw new ArgumentNullException(nameof(from)); + } + + if (to is null) + { + throw new ArgumentNullException(nameof(to)); + } + + return str.GetBytes(from).GetString(to); + } + /// /// Parses a into an . ///