本文整理汇总了C#中System.Text.UTF7Encoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# UTF7Encoding.GetBytes方法的具体用法?C# UTF7Encoding.GetBytes怎么用?C# UTF7Encoding.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF7Encoding
的用法示例。
在下文中一共展示了UTF7Encoding.GetBytes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest2
public void PosTest2()
{
Byte[] bytes;
Char[] chars = new Char[] { };
UTF7Encoding UTF7 = new UTF7Encoding();
int byteCount = UTF7.GetByteCount(chars, 0, 0);
bytes = new Byte[byteCount];
int bytesEncodedCount = UTF7.GetBytes(chars, 0, 0, bytes, 0);
Assert.Equal(0, bytesEncodedCount);
}
示例2: Decode7Bit
protected byte[] Decode7Bit(string value)
{
try
{
UTF7Encoding utf7 = new UTF7Encoding();
return utf7.GetBytes(value);
}
catch
{
return null;
}
}
示例3: NegTest1
public void NegTest1()
{
Byte[] bytes;
Char[] chars = null;
UTF7Encoding UTF7 = new UTF7Encoding();
int byteCount = 10;
bytes = new Byte[byteCount];
Assert.Throws<ArgumentNullException>(() =>
{
int bytesEncodedCount = UTF7.GetBytes(chars, 1, 2, bytes, 0);
});
}
示例4: PosTest1
public void PosTest1()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF7Encoding UTF7 = new UTF7Encoding();
int byteCount = UTF7.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int bytesEncodedCount = UTF7.GetBytes(chars, 1, 2, bytes, 0);
}
示例5: NegTest2
public void NegTest2()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF7Encoding UTF7 = new UTF7Encoding();
int byteCount = UTF7.GetByteCount(chars, 1, 2);
bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
int bytesEncodedCount = UTF7.GetBytes(chars, 1, 2, bytes, 0);
});
}
示例6: TestDirectlyEncoded1
public void TestDirectlyEncoded1()
{
// Unicode characters a-z, A-Z, 0-9 and '()_./:? are directly encoded.
string UniCodeString = "\u0061\u007A\u0041\u005A\u0030\u0039\u0027\u003F";
byte[] UTF7Bytes = null;
UTF7Encoding UTF7enc = new UTF7Encoding ();
UTF7Bytes = UTF7enc.GetBytes (UniCodeString);
Assertion.AssertEquals ("UTF7 #1", 0x61, UTF7Bytes [0]);
Assertion.AssertEquals ("UTF7 #2", 0x7A, UTF7Bytes [1]);
Assertion.AssertEquals ("UTF7 #3", 0x41, UTF7Bytes [2]);
Assertion.AssertEquals ("UTF7 #4", 0x5A, UTF7Bytes [3]);
Assertion.AssertEquals ("UTF7 #5", 0x30, UTF7Bytes [4]);
Assertion.AssertEquals ("UTF7 #6", 0x39, UTF7Bytes [5]);
Assertion.AssertEquals ("UTF7 #7", 0x27, UTF7Bytes [6]);
Assertion.AssertEquals ("UTF7 #8", 0x3F, UTF7Bytes [7]);
}
示例7: TestDirectlyEncoded2
public void TestDirectlyEncoded2()
{
// Unicode characters a-z, A-Z, 0-9 and '()_./:? are directly encoded.
string UniCodeString = "\u0061\u007A\u0041\u005A\u0030\u0039\u0027\u003F";
byte[] UTF7Bytes = new byte [8];
int Length = UniCodeString.Length;
UTF7Encoding UTF7enc = new UTF7Encoding ();
int Cnt = UTF7enc.GetBytes (UniCodeString.ToCharArray(), 0, Length, UTF7Bytes, 0);
Assert.AreEqual (0x61, UTF7Bytes [0], "UTF7 #1");
Assert.AreEqual (0x7A, UTF7Bytes [1], "UTF7 #2");
Assert.AreEqual (0x41, UTF7Bytes [2], "UTF7 #3");
Assert.AreEqual (0x5A, UTF7Bytes [3], "UTF7 #4");
Assert.AreEqual (0x30, UTF7Bytes [4], "UTF7 #5");
Assert.AreEqual (0x39, UTF7Bytes [5], "UTF7 #6");
Assert.AreEqual (0x27, UTF7Bytes [6], "UTF7 #7");
Assert.AreEqual (0x3F, UTF7Bytes [7], "UTF7 #8");
}
示例8: TestEncodeOptionalEncoded
public void TestEncodeOptionalEncoded()
{
string UniCodeString = "\u0021\u0026\u002A\u003B";
byte[] UTF7Bytes = null;
//Optional Characters are allowed.
UTF7Encoding UTF7enc = new UTF7Encoding (true);
UTF7Bytes = UTF7enc.GetBytes (UniCodeString);
Assertion.AssertEquals ("UTF7 #1", 0x21, UTF7Bytes [0]);
Assertion.AssertEquals ("UTF7 #2", 0x26, UTF7Bytes [1]);
Assertion.AssertEquals ("UTF7 #3", 0x2A, UTF7Bytes [2]);
Assertion.AssertEquals ("UTF7 #4", 0x3B, UTF7Bytes [3]);
//Optional characters are not allowed.
UTF7enc = new UTF7Encoding (false);
UTF7Bytes = UTF7enc.GetBytes (UniCodeString);
Assertion.AssertEquals ("UTF7 #5", 0x2B, UTF7Bytes [0]);
Assertion.AssertEquals ("UTF7 #6", 0x41, UTF7Bytes [1]);
Assertion.AssertEquals ("UTF7 #7", 0x43, UTF7Bytes [2]);
Assertion.AssertEquals ("UTF7 #8", 0x45, UTF7Bytes [3]);
Assertion.AssertEquals ("UTF7 #6", 0x41, UTF7Bytes [1]);
}
示例9: GetUniStrRandAnsiBytes
//-------------------------------------------------------------------------------
// Name : GetUniStrRandAnsiBytes
// Purpose : This function returns a Byte array of Unicode,UTF7 or UTF8 characters.
// Inputs : iMaxChar -- maximum number of character to be generated
// : bAbsolute -- if set true, exact number (iMaxChar) will be generated,
// if set falise, number of generated chars will be random.
// : bValidate -- boolean, if true, verify generated characters are valid
// if false, does not verify generated characters
// : intType -- Type of conversion to make. CODE_UNI, CODE_UTF7, CODE_UTF8.
// Note : enulcidType -- Locale ID.
//-------------------------------------------------------------------------------
public Byte[] GetUniStrRandAnsiBytes(int iMaxChar, bool bAbsolute, bool bValidate, enuCodeType intCodeType, enuLCIDList enulcidType, bool bNoLeadNum ){
String strText;
Byte[] bArrEncoded = null;
int iOldLCID = iCurrentLCID ;
VerifyLCIDAndLoadResource( (int)enulcidType );
if ( iMaxChar <= 0 ) // If the string length is <= zero, return an empty string
return bArrEncoded;
if ((int)intCodeType < 0 || (int)intCodeType > 3) // invalid conversion type
intCodeType = enuCodeType.CURRENT; //use default system code page.
strText = GetString( iMaxChar, bAbsolute, bValidate );
switch( intCodeType ){
case enuCodeType.CODE_UTF8:
UTF8Encoding encUTF8 = new UTF8Encoding();
bArrEncoded = encUTF8.GetBytes( strText );
break ;
case enuCodeType.CODE_UTF7:
UTF7Encoding encUTF7 = new UTF7Encoding();
bArrEncoded = encUTF7.GetBytes( strText );
break ;
case enuCodeType.CODE_UNI:
UnicodeEncoding encUnicode = new UnicodeEncoding();
bArrEncoded = encUnicode.GetBytes( strText );
break ;
case enuCodeType.CURRENT: //In case if you need the encoding bytes for default system code page.
Encoding encode = Encoding.Default;
bArrEncoded = encode.GetBytes( strText );
break;
default:
break ;
}
VerifyLCIDAndLoadResource( iOldLCID );
return bArrEncoded ;
}
示例10: WriteUDTString
public void WriteUDTString(string tagName, string value)
{
lock (mSyncLock) {
Logix.Tag lengthTag = new Logix.Tag(tagName + ".LEN");
Logix.Tag dataTag = new Logix.Tag(tagName + ".DATA[0]");
System.Text.UTF7Encoding utf = new System.Text.UTF7Encoding();
// * set the DataType properties
lengthTag.DataType = Logix.Tag.ATOMIC.DINT;
dataTag.DataType = Logix.Tag.ATOMIC.SINT;
lengthTag.Value = value.Length;
dataTag.Length = value.Length;
dataTag.Value = utf.GetBytes(value);
WriteTag(lengthTag);
WriteTag(dataTag);
}
}
示例11: TestEncodeUnicodeShifted1
public void TestEncodeUnicodeShifted1()
{
string UniCodeString = "\u0041\u2262\u0391\u002E";
byte[] UTF7Bytes = null;
UTF7Encoding UTF7enc = new UTF7Encoding();
UTF7Bytes = UTF7enc.GetBytes (UniCodeString);
//"A<NOT IDENTICAL TO><ALPHA>." is encoded as A+ImIDkQ-. see RFC 1642
Assertion.AssertEquals ("UTF7 #1", 0x41, UTF7Bytes [0]);
Assertion.AssertEquals ("UTF7 #2", 0x2B, UTF7Bytes [1]);
Assertion.AssertEquals ("UTF7 #3", 0x49, UTF7Bytes [2]);
Assertion.AssertEquals ("UTF7 #4", 0x6D, UTF7Bytes [3]);
Assertion.AssertEquals ("UTF7 #5", 0x49, UTF7Bytes [4]);
Assertion.AssertEquals ("UTF7 #6", 0x44, UTF7Bytes [5]);
Assertion.AssertEquals ("UTF7 #7", 0x6B, UTF7Bytes [6]);
Assertion.AssertEquals ("UTF7 #8", 0x51, UTF7Bytes [7]);
Assertion.AssertEquals ("UTF7 #9", 0x2D, UTF7Bytes [8]);
Assertion.AssertEquals ("UTF7 #10", 0x2E, UTF7Bytes [9]);
}
示例12: TestEncodeUnicodeShifted2
public void TestEncodeUnicodeShifted2()
{
string UniCodeString = "\u0041\u2262\u0391\u002E";
byte[] UTF7Bytes = new byte [10];
int Length = UniCodeString.Length;
UTF7Encoding UTF7enc = new UTF7Encoding ();
int Cnt = UTF7enc.GetBytes (UniCodeString.ToCharArray(), 0, Length, UTF7Bytes, 0);
//"A<NOT IDENTICAL TO><ALPHA>." is encoded as A+ImIDkQ-. see RFC 1642
Assert.AreEqual (0x41, UTF7Bytes [0], "UTF7 #1");
Assert.AreEqual (0x2B, UTF7Bytes [1], "UTF7 #2");
Assert.AreEqual (0x49, UTF7Bytes [2], "UTF7 #3");
Assert.AreEqual (0x6D, UTF7Bytes [3], "UTF7 #4");
Assert.AreEqual (0x49, UTF7Bytes [4], "UTF7 #5");
Assert.AreEqual (0x44, UTF7Bytes [5], "UTF7 #6");
Assert.AreEqual (0x6B, UTF7Bytes [6], "UTF7 #7");
Assert.AreEqual (0x51, UTF7Bytes [7], "UTF7 #8");
Assert.AreEqual (0x2D, UTF7Bytes [8], "UTF7 #9");
Assert.AreEqual (0x2E, UTF7Bytes [9], "UTF7 #10");
}
示例13: NegTest8
public void NegTest8()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF7Encoding UTF7 = new UTF7Encoding();
int byteCount = UTF7.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
int bytesEncodedCount = UTF7.GetBytes(chars, chars.Length, 2, bytes, 1);
});
}