【问题标题】:Last character of a Tamil unicode string泰米尔语 unicode 字符串的最后一个字符
【发布时间】:2014-03-11 05:03:35
【问题描述】:

如何获取 unicode 泰米尔语字符串的最后一个字符。 例如,我有一个字符串列表,如"சுதீப்", "செய்தியை", "கொள்ளாதது", "வில்லன்"

如果我对上述字符串使用 mystring.Last() 我得到了

"சுதீப்" = ""்"" “செய்தியை” = "ை “கொள்ளாதது”=""ு"" "வில்லன்" = ""்""

但我需要得到

"சுதீப்" = ""ப்"" “செய்தியை” = ""யை"" “கொள்ளாதது”=""து"" "வில்லன்" = ""ன்""

【问题讨论】:

    标签: vb.net unicode-string


    【解决方案1】:

    我建议您创建一个辅助函数,在其中循环遍历每个字符并检查 UnicodeCategory

    扩展

    <System.Runtime.CompilerServices.Extension()> _
    Public Module StringExtensions
    
        <System.Runtime.CompilerServices.Extension()> _
        Public Function Split(str As String, category As UnicodeCategory) As IList(Of String)
            Dim list As New List(Of String)
            If ((Not str Is Nothing) AndAlso (str.Length > 0)) Then
                Dim item As String = Nothing
                Dim chr As Char = Nothing
                For Each chr In str
                    If (Char.GetUnicodeCategory(chr) = category) Then
                        If ((Not item Is Nothing) AndAlso (item.Length > 0)) Then
                            list.Add(item)
                        End If
                        item = chr
                    Else
                        item += chr
                    End If
                Next
                If ((Not item Is Nothing) AndAlso (item.Length > 0)) Then
                    list.Add(item)
                End If
            End If
            Return list
        End Function
    
    End Module
    

    用法

    Imports [your_namespace].StringExtensions
    
    Dim values As String() = {"சுதீப்", "செய்தியை", "கொள்ளாதது", "வில்லன்"}
    Dim builder As New System.Text.StringBuilder()
    
    For Each item As String In values
        builder.AppendLine(String.Concat(item, " : ", item.Split(UnicodeCategory.OtherLetter).Last()))
    Next
    
    MessageBox.Show(builder.ToString())
    

    输出

    சுதீப் : ப்
    செய்தியை : யை
    கொள்ளாதது : து
    வில்லன் : ன்
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 2012-04-02
      • 1970-01-01
      • 2012-02-06
      • 2014-07-18
      相关资源
      最近更新 更多