/// <summary> /// Modifies the message text so that it is safe to be sent via GSM 7-Bit default encoding. /// </summary> /// <param name="data">The message text.</param> /// <param name="charsCorrected">Will be set to true if the message length was corrected.</param> /// <param name="lengthCorrected">Will be set to true if one or more characters were replaced.</param> /// <returns>The converted message text.</returns> /// <remarks>Replaces invalid characters in the text and truncates it to the maximum allowed length.</remarks> public static string GetSafeText(string data, out bool lengthCorrected, out bool charsCorrected) { string str; string str1; bool flag = false; lengthCorrected = false; charsCorrected = false; if (data.Length <= 160) { str = data; } else { str = data.Substring(0, 160); lengthCorrected = true; } do { str1 = TextDataConverter.StringTo7Bit(str, false, out flag); if (flag) { charsCorrected = true; } if (str1.Length <= 160) { continue; } str = data.Substring(0, str.Length - 1); lengthCorrected = true; }while (str1.Length > 160); string str2 = TextDataConverter.SevenBitToString(str1); return(str2); }
/// <summary> /// Converts a string consisting of characters from the GSM /// "7-bit default alphabet" into a string of corresponding characters /// of the ISO-8859-1 character set. /// </summary> /// <param name="s">The string to convert.</param> /// <returns>The converted string.</returns> /// <remarks> /// <para>Note that the converted string does not necessarily have the same /// length as the original one because some characters may be escaped.</para> /// <para>This method throws an exception if an invalid character /// is encountered.</para> /// </remarks> public static string SevenBitToString(string s) { return(TextDataConverter.SevenBitToString(s, true)); }
/// <summary> /// Decodes the text from 7-Bit user data. /// </summary> /// <param name="userData">The user data to decode. Must contain an encoded GSM 7-Bit default text packed into octets.</param> /// <returns>The decoded user data.</returns> public static string Decode7BitText(byte[] userData) { string septetsStr = TextDataConverter.OctetsToSeptetsStr(userData); return(TextDataConverter.SevenBitToString(septetsStr, true)); }