当前位置: 首页>>代码示例>>C#>>正文


C# UTF7Encoding.GetString方法代码示例

本文整理汇总了C#中System.Text.UTF7Encoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# UTF7Encoding.GetString方法的具体用法?C# UTF7Encoding.GetString怎么用?C# UTF7Encoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UTF7Encoding的用法示例。


在下文中一共展示了UTF7Encoding.GetString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decompress

        public string Decompress(string filename)
        {
            StringBuilder result = null;

            try
            {
                Stream s = new GZipInputStream(File.OpenRead(filename));

                result = new StringBuilder(8192);
                UTF7Encoding encoding = new UTF7Encoding(true);

                int size = 2048;
                byte[] writeData = new byte[2048];
                while (true)
                {
                    size = s.Read(writeData, 0, size);
                    if (size > 0)
                    {
                       result.Append(encoding.GetString(writeData,0,size));
                    }
                    else
                    {
                        break;
                    }
                }
                s.Close();

            } // end try
            catch (GZipException)
            {
                throw new Exception("Error: The file being read contains invalid data.");
            }
            catch (FileNotFoundException)
            {
                throw new Exception("Error:The file specified was not found.");
            }
            catch (ArgumentException)
            {
                throw new Exception("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
            }
            catch (PathTooLongException)
            {
                throw new Exception("Error: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
            }
            catch (DirectoryNotFoundException)
            {
                throw new Exception("Error: The specified path is invalid, such as being on an unmapped drive.");
            }
            catch (IOException)
            {
                throw new Exception("Error: An I/O error occurred while opening the file.");
            }
            catch (UnauthorizedAccessException)
            {
                throw new Exception("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
            }

            return result.ToString();
        }
开发者ID:BackupTheBerlios,项目名称:dufftv-svn,代码行数:59,代码来源:GzipDecompressor.cs

示例2: NegTest1

 public void NegTest1()
 {
     Byte[] bytes = null;
     UTF7Encoding utf7 = new UTF7Encoding();
     Assert.Throws<ArgumentNullException>(() =>
     {
         string str = utf7.GetString(bytes, 0, 2);
     });
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:9,代码来源:UTF7EncodingGetString.cs

示例3: PosTest1

 public void PosTest1()
 {
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     UTF7Encoding utf7 = new UTF7Encoding();
     string str = utf7.GetString(bytes, 0, bytes.Length);
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:9,代码来源:UTF7EncodingGetString.cs

示例4: NegTest3

 public void NegTest3()
 {
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     UTF7Encoding utf7 = new UTF7Encoding();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         string str = utf7.GetString(bytes, 0, -1);
     });
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:UTF7EncodingGetString.cs

示例5: PosTest2

 public void PosTest2()
 {
     int startIndex = 0;
     int count = 0;
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     startIndex = _generator.GetInt32(-55) % bytes.Length;
     count = _generator.GetInt32(-55) % (bytes.Length - startIndex) + 1;
     UTF7Encoding utf7 = new UTF7Encoding();
     string str = utf7.GetString(bytes, startIndex, count);
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:13,代码来源:UTF7EncodingGetString.cs

示例6: ReadUDTString

        public string ReadUDTString(string tagName)
        {
            lock (mSyncLock) {
                System.Text.UTF7Encoding utf = new System.Text.UTF7Encoding();

                Logix.Tag lengthTag = new Logix.Tag(tagName + ".LEN");
                Logix.Tag dataTag = new Logix.Tag(tagName + ".DATA[0]");

                ReadTag(lengthTag);

                dataTag.Length = (int)lengthTag.Value;
                ReadTag(dataTag);

                if (dataTag.Value is sbyte) {
                    return Convert.ToChar(dataTag.Value).ToString();
                } else if (dataTag.Value is System.Array) {
                    byte[] b = (byte[])dataTag.Value;
                    return utf.GetString(b, 0, dataTag.Length);
                } else {
                    throw new LogixTagException("Invalid tag type.", dataTag, 0);
                }
            }
        }
开发者ID:eprimo,项目名称:Linc-Reporting-Service,代码行数:23,代码来源:Logix.cs

示例7: RFC1642_Example4

		public void RFC1642_Example4 ()
		{
			string UniCodeString = "\u0049\u0074\u0065\u006D\u0020\u0033\u0020\u0069\u0073\u0020\u00A3\u0031\u002E";
			char[] expected = UniCodeString.ToCharArray ();

			byte[] UTF7Bytes = new byte[] { 0x49, 0x74, 0x65, 0x6D, 0x20, 0x33, 0x20, 0x69, 0x73, 0x20, 0x2B, 0x41, 0x4B, 0x4D, 0x2D, 0x31, 0x2E };

			UTF7Encoding UTF7enc = new UTF7Encoding ();
			char[] actual = UTF7enc.GetChars (UTF7Bytes);

			// "Item 3 is +AKM-1." is decoded as "Item 3 is <POUND SIGN>1."
			AssertEquals ("UTF #1", expected [0], actual [0]);
			AssertEquals ("UTF #2", expected [1], actual [1]);
			AssertEquals ("UTF #3", expected [2], actual [2]);
			AssertEquals ("UTF #4", expected [3], actual [3]);
			AssertEquals ("UTF #5", expected [4], actual [4]);
			AssertEquals ("UTF #6", expected [5], actual [5]);
			AssertEquals ("UTF #7", expected [6], actual [6]);
			AssertEquals ("UTF #8", expected [7], actual [7]);
			AssertEquals ("UTF #9", expected [8], actual [8]);
			AssertEquals ("UTF #10", expected [9], actual [9]);
			AssertEquals ("UTF #11", expected [10], actual [10]);
			AssertEquals ("UTF #12", expected [11], actual [11]);
			AssertEquals ("UTF #13", expected [12], actual [12]);

			AssertEquals ("GetString", UniCodeString, UTF7enc.GetString (UTF7Bytes));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:UTF7EncodingTest.cs

示例8: RFC1642_Example3

		public void RFC1642_Example3 ()
		{
			string UniCodeString = "\u65E5\u672C\u8A9E";
			char[] expected = UniCodeString.ToCharArray ();

			byte[] UTF7Bytes = new byte[] { 0x2B, 0x5A, 0x65, 0x56, 0x6E, 0x4C, 0x49, 0x71, 0x65, 0x2D };

			UTF7Encoding UTF7enc = new UTF7Encoding ();
			char[] actual = UTF7enc.GetChars (UTF7Bytes);

			// "+ZeVnLIqe-" is decoded as Japanese "nihongo"
			AssertEquals ("UTF #1", expected [0], actual [0]);
			AssertEquals ("UTF #2", expected [1], actual [1]);
			AssertEquals ("UTF #3", expected [2], actual [2]);

			AssertEquals ("GetString", UniCodeString, UTF7enc.GetString (UTF7Bytes));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:17,代码来源:UTF7EncodingTest.cs

示例9: RFC1642_Example2

		public void RFC1642_Example2 ()
		{
			string UniCodeString = "\u0048\u0069\u0020\u004D\u006F\u004D\u0020\u263A\u0021";
			char[] expected = UniCodeString.ToCharArray ();

			byte[] UTF7Bytes = new byte[] { 0x48, 0x69, 0x20, 0x4D, 0x6F, 0x4D, 0x20, 0x2B, 0x4A, 0x6A, 0x6F, 0x41, 0x49, 0x51, 0x2D };

			UTF7Encoding UTF7enc = new UTF7Encoding ();
			char[] actual = UTF7enc.GetChars (UTF7Bytes);

			// "Hi Mom +Jjo-!" is decoded as "Hi Mom <WHITE SMILING FACE>!"
			AssertEquals ("UTF #1", expected [0], actual [0]);
			AssertEquals ("UTF #2", expected [1], actual [1]);
			AssertEquals ("UTF #3", expected [2], actual [2]);
			AssertEquals ("UTF #4", expected [3], actual [3]);
			AssertEquals ("UTF #5", expected [4], actual [4]);
			AssertEquals ("UTF #6", expected [5], actual [5]);
			AssertEquals ("UTF #7", expected [6], actual [6]);
			AssertEquals ("UTF #8", expected [7], actual [7]);
			AssertEquals ("UTF #9", expected [8], actual [8]);

			AssertEquals ("GetString", UniCodeString, UTF7enc.GetString (UTF7Bytes));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:23,代码来源:UTF7EncodingTest.cs

示例10: RFC1642_Example1

		public void RFC1642_Example1 ()
		{
			string UniCodeString = "\u0041\u2262\u0391\u002E";
			char[] expected = UniCodeString.ToCharArray ();

			byte[] UTF7Bytes = new byte [] {0x41, 0x2B, 0x49, 0x6D, 0x49, 0x44, 0x6B,  0x51, 0x2D, 0x2E};
			UTF7Encoding UTF7enc = new UTF7Encoding ();
			char[] actual = UTF7enc.GetChars (UTF7Bytes);

			// "A+ImIDkQ-." is decoded as "A<NOT IDENTICAL TO><ALPHA>." see RFC 1642
			AssertEquals ("UTF #1", expected [0], actual [0]);
			AssertEquals ("UTF #2", expected [1], actual [1]);
			AssertEquals ("UTF #3", expected [2], actual [2]);
			AssertEquals ("UTF #4", expected [3], actual [3]);

			AssertEquals ("GetString", UniCodeString, UTF7enc.GetString (UTF7Bytes));
                }
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:17,代码来源:UTF7EncodingTest.cs

示例11: Scan

 public string Scan()
 {
     if (dispositivo_aberto && !Ocupado())
     {
         string dadoss = string.Empty;
         UTF7Encoding enc = new UTF7Encoding();
         int tamanho=155;
         byte[] dados = new byte[tamanho];
         dispositivo.SendControlMessage(descritor.VendorId | (1 << 7), (int)Comando.USB_FUNC_SCAN, tamanho, dados);
         dadoss += enc.GetString(dados);
         return dadoss;
     }
     else
     {
         return string.Empty;
     }
 }
开发者ID:roboime,项目名称:legacy-roboime,代码行数:17,代码来源:Transmissor.cs

示例12: Receber

 /// <summary>Recebe dados do dispositivo.
 /// </summary>
 public string Receber()
 {
     if (dispositivo_aberto && !Ocupado())
     {
         string dadoss = string.Empty;
         UTF7Encoding enc = new UTF7Encoding();
         byte[] dados = new byte[8];
         dispositivo.SendControlMessage(descritor.VendorId | (1 << 7), 4, 3, dados);
         int tamanho = dados[1];
         if (tamanho > 0)
         {
             Array.Resize(ref dados, tamanho);
             dispositivo.SendControlMessage(descritor.VendorId | (1 << 7), 5, tamanho, dados);
             dadoss += enc.GetString(dados);
             return dadoss;
         }
         else
         {
             //                throw new Exception("Dispositivo não inicializado.");
             return string.Empty;
         }
     }
     else
     {
         //                throw new Exception("Dispositivo não inicializado.");
         return string.Empty;
     }
 }
开发者ID:roboime,项目名称:legacy-roboime,代码行数:30,代码来源:Transmissor.cs

示例13: Encode7Bit

 protected string Encode7Bit(byte[] data)
 {
     try
     {
         UTF7Encoding utf7 = new UTF7Encoding();
         return utf7.GetString(data);
     }
     catch
     {
         return null;
     }
 }
开发者ID:logikonline,项目名称:DDay.iCal,代码行数:12,代码来源:EncodingProvider.cs


注:本文中的System.Text.UTF7Encoding.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。