本文整理汇总了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;
}
示例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());
}
示例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");
}
示例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));
}
示例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));
}
示例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);
}
示例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());
}
示例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);
}
示例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()));
}
}
示例10: TestNullReference
public void TestNullReference()
{
string str = null;
Assert.Throws<ArgumentNullException>(() =>
{
StringInfo stringInfo = new StringInfo(str);
});
}
示例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;
}
示例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 };
}
示例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);
}
示例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;
}
}
示例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);
}