• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Globalization.StringInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Globalization.StringInfo的典型用法代码示例。如果您正苦于以下问题:C# StringInfo类的具体用法?C# StringInfo怎么用?C# StringInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StringInfo类属于System.Globalization命名空间,在下文中一共展示了StringInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetTweetLength

        /// <summary>
        /// 
        /// </summary>
        /// <param name="text">Target of string. Should be normalized 'NormalizationForm.FormC'</param>
        /// <returns></returns>
        public int GetTweetLength(String text)
        {
            try
            {
                //text = text.Normalize(NormalizationForm.FormC);
            }
            catch { }

            int length = new StringInfo(text).LengthInTextElements;
            foreach (Extractor.Entity urlEntity in __Extractor.ExtractURLsWithIndices(text))
            {
                // Subtract the length of the original URL
                length -= (urlEntity.End - urlEntity.Start);

                // Add `ShortUrlLengthHttps` characters for URL starting with https:// Otherwise add `ShortUrlLength` characters
                length += urlEntity.Value.ToLower().StartsWith("https://") ? ShortUrlLengthHttps : ShortUrlLength;
            }
            return length;
        }
开发者ID:niltz,项目名称:twitter-text-cs,代码行数:24,代码来源:Validator.cs


示例17: VerificationHelper

 private void VerificationHelper(string str, int expected)
 {
     StringInfo stringInfo = new StringInfo(str);
     int result = stringInfo.LengthInTextElements;
     Assert.Equal(expected, result);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:6,代码来源:StringInfoLengthInTextElements.cs


示例18: TestCtorWithWhitespace

 public void TestCtorWithWhitespace()
 {
     string str = " ";
     StringInfo stringInfo = new StringInfo(str);
     Assert.Equal(" ", stringInfo.String);
 }
开发者ID:qskycolor,项目名称:corefx,代码行数:6,代码来源:StringInfoCtor2.cs


示例19: ConvertToCharIndex

 private static int ConvertToCharIndex(int index, string text)
 {
     if (index <= 0)
     {
         return 0;
     }
     if (string.IsNullOrEmpty(text))
     {
         return index;
     }
     StringInfo info = new StringInfo(text);
     int lengthInTextElements = info.LengthInTextElements;
     if (index > lengthInTextElements)
     {
         return ((index - lengthInTextElements) + text.Length);
     }
     return info.SubstringByTextElements(0, index).Length;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:LinkLabel.cs


示例20: IsOneLink

 private bool IsOneLink()
 {
     if (((this.links == null) || (this.links.Count != 1)) || (this.Text == null))
     {
         return false;
     }
     StringInfo info = new StringInfo(this.Text);
     return ((this.LinkArea.Start == 0) && (this.LinkArea.Length == info.LengthInTextElements));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:LinkLabel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Globalization.TaiwanCalendar类代码示例发布时间:2022-05-26
下一篇:
C# Globalization.RegionInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap