當前位置: 首頁>>代碼示例>>C#>>正文


C# Globalization.StringInfo類代碼示例

本文整理匯總了C#中System.Globalization.StringInfo的典型用法代碼示例。如果您正苦於以下問題:C# StringInfo類的具體用法?C# StringInfo怎麽用?C# StringInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringInfo類屬於System.Globalization命名空間,在下文中一共展示了StringInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AdjustCharacterRangesForSurrogateChars

 private CharacterRange[] AdjustCharacterRangesForSurrogateChars()
 {
     string text = this.Text;
     if (string.IsNullOrEmpty(text))
     {
         return new CharacterRange[0];
     }
     StringInfo info = new StringInfo(text);
     int lengthInTextElements = info.LengthInTextElements;
     ArrayList list = new ArrayList(this.Links.Count);
     foreach (Link link in this.Links)
     {
         int start = ConvertToCharIndex(link.Start, text);
         int num3 = ConvertToCharIndex(link.Start + link.Length, text);
         if (this.LinkInText(start, num3 - start))
         {
             int num4 = Math.Min(link.Length, lengthInTextElements - link.Start);
             list.Add(new CharacterRange(start, ConvertToCharIndex(link.Start + num4, text) - start));
         }
     }
     CharacterRange[] array = new CharacterRange[list.Count + 1];
     list.CopyTo(array, 0);
     array[array.Length - 1] = new CharacterRange(0, text.Length);
     return array;
 }
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:25,代碼來源:LinkLabel.cs

示例2: TestDiffInstances

 public void TestDiffInstances()
 {
     string str = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
     StringInfo stringInfo1 = new StringInfo(str);
     StringInfo stringInfo2 = new StringInfo("");
     Assert.NotEqual(stringInfo2.GetHashCode(), stringInfo1.GetHashCode());
 }
開發者ID:misterzik,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoGetHashCode.cs

示例3: SubstringByTextElements

		public void SubstringByTextElements ()
		{
			StringInfo si = new StringInfo ("A\u0330BC\u0330");
			Assert.AreEqual ("A\u0330BC\u0330", si.SubstringByTextElements (0), "#1");
			Assert.AreEqual ("BC\u0330", si.SubstringByTextElements (1), "#2");
			Assert.AreEqual ("C\u0330", si.SubstringByTextElements (2), "#3");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:7,代碼來源:StringInfoTest.cs

示例4: TestSameReference

 public void TestSameReference()
 {
     string str = _generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
     StringInfo stringInfo1 = new StringInfo(str);
     StringInfo stringInfo2 = stringInfo1;
     Assert.True(stringInfo1.Equals(stringInfo2));
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoEquals.cs

示例5: TestEqualStringInfoWithArg

 public void TestEqualStringInfoWithArg()
 {
     string str = _generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
     StringInfo stringInfo1 = new StringInfo(str);
     StringInfo stringInfo2 = new StringInfo(str);
     Assert.True(stringInfo1.Equals(stringInfo2));
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoEquals.cs

示例6: TestSetProperty

 public void TestSetProperty()
 {
     string str = _generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
     StringInfo stringInfo = new StringInfo();
     stringInfo.String = str;
     Assert.Equal(str, stringInfo.String);
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoString.cs

示例7: TestInstancesWithSameArg

 public void TestInstancesWithSameArg()
 {
     string str = _generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
     StringInfo stringInfo1 = new StringInfo(str);
     StringInfo stringInfo2 = new StringInfo(str);
     Assert.Equal(stringInfo2.GetHashCode(), stringInfo1.GetHashCode());
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoGetHashCode.cs

示例8: String_Set

 public void String_Set()
 {
     string value = s_randomDataGenerator.GetString(-55, false, MinStringLength, MaxStringLength);
     StringInfo stringInfo = new StringInfo();
     stringInfo.String = value;
     Assert.Equal(value, stringInfo.String);
 }
開發者ID:benpye,項目名稱:corefx,代碼行數:7,代碼來源:StringInfoString.cs

示例9: Equals

 public void Equals(StringInfo stringInfo, object value, bool expected)
 {
     Assert.Equal(expected, stringInfo.Equals(value));
     if (value is StringInfo)
     {
         Assert.Equal(expected, stringInfo.GetHashCode().Equals(value.GetHashCode()));
     }
 }
開發者ID:benpye,項目名稱:corefx,代碼行數:8,代碼來源:StringInfoEquals.cs

示例10: TestNullReference

 public void TestNullReference()
 {
     string str = null;
     Assert.Throws<ArgumentNullException>(() =>
     {
         StringInfo stringInfo = new StringInfo(str);
     });
 }
開發者ID:qskycolor,項目名稱:corefx,代碼行數:8,代碼來源:StringInfoCtor2.cs

示例11: CapitalizeFirstLetter

 public static string CapitalizeFirstLetter(this string s, CultureInfo ci = null)
 {
     var si = new StringInfo(s);
     if (ci == null)
         ci = CultureInfo.CurrentCulture;
     if (si.LengthInTextElements > 0)
         s = si.SubstringByTextElements(0, 1).ToUpper(ci);
     if (si.LengthInTextElements > 1)
         s += si.SubstringByTextElements(1);
     return s;
 }
開發者ID:Gargamelll,項目名稱:subtitleedit,代碼行數:11,代碼來源:StringExtensions.cs

示例12: Equals_TestData

 public static IEnumerable<object[]> Equals_TestData()
 {
     string randomString = s_randomDataGenerator.GetString(-55, false, MinStringLength, MaxStringLength);
     StringInfo randomStringInfo = new StringInfo(randomString);
     yield return new object[] { randomStringInfo, new StringInfo(randomString), true };
     yield return new object[] { randomStringInfo, randomStringInfo, true };
     yield return new object[] { new StringInfo(), new StringInfo(), true };
     yield return new object[] { new StringInfo("stringinfo1"), new StringInfo("stringinfo2"), false };
     yield return new object[] { new StringInfo("stringinfo1"), "stringinfo1", false };
     yield return new object[] { new StringInfo("stringinfo1"), 123, false };
     yield return new object[] { new StringInfo("stringinfo1"), null, false };
 }
開發者ID:benpye,項目名稱:corefx,代碼行數:12,代碼來源:StringInfoEquals.cs

示例13: CanCalculateLength

        public void CanCalculateLength()
        {
            var str = "ไม่เอาเห็ด";
            var length = new StringInfo(str).LengthInTextElements;
            Assert.AreEqual(8, length);

            str = "123456";
            length = new StringInfo(str).LengthInTextElements;
            Assert.AreEqual(6, length);

            str = "âl'a";
            length = new StringInfo(str).LengthInTextElements;
            Assert.AreEqual(4, length);
        }
開發者ID:jgera,項目名稱:SambaPOS-3,代碼行數:14,代碼來源:PrinterTests.cs

示例14: Truncate

        public static string Truncate(this HtmlHelper helper, string input, int length, string omission)
        {
            // http://dobon.net/vb/dotnet/string/substring.html
            
            StringInfo si = new StringInfo(input);

            if (si.LengthInTextElements <= length)
            {
                return input;
            }
            else
            {
                return si.SubstringByTextElements(0, length) + omission;
            }
        }
開發者ID:wulab,項目名稱:prototype.net,代碼行數:15,代碼來源:HtmlHelpers.cs

示例15: SurrogatePairValid

    public void SurrogatePairValid()
    {
      string json = @"{ ""MATHEMATICAL ITALIC CAPITAL ALPHA"": ""\uD835\uDEE2"" }";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));

      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      string s = reader.Value.ToString();
      Assert.AreEqual(2, s.Length);

      StringInfo stringInfo = new StringInfo(s);
      Assert.AreEqual(1, stringInfo.LengthInTextElements);
    }
開發者ID:plurby,項目名稱:Newtonsoft.Json,代碼行數:18,代碼來源:JsonTextReaderTest.cs


注:本文中的System.Globalization.StringInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。