Home > OS >  VB.Net, How to get the String Value
VB.Net, How to get the String Value

Time:11-27

Here is my function to normal string to alpha numeric for requirement

    Public Function ToModern(_cond$)
      Dim _A% = 0 : Dim _B% = 0, _C% = 0
      Dim _mdSt$ = ""
      _A% = _cond$.Count(Function(x) x = "A")
      _B% = _cond$.Count(Function(x) x = "B")
      _C% = _cond$.Count(Function(x) x = "C")
      _mdSt = $"{_A%}A{_B%}B{_C}C"

     Return _mdSt$
   End Function

working fine and answer is

    Public Function Test()
       Trace.WriteLine(ToModern("AAABBBCCC")) '3A3B3C
       Trace.WriteLine(ToModern("CCCCBBBAAA")) '3A3B4C
       Trace.WriteLine(ToModern("BBAACCCC")) '2A2B4C
    End Function

ToModern("AAABBBCCC")) '3A3B3Cis correct but the second one want to like 3C3B3A instead the result how to achieve this

CodePudding user response:

    Public Function ToModern(_cond$)
    Dim result As String = String.Empty
    For Each s As String In _cond$.ToList().Distinct()
        result = result & (From c In _cond$.ToList() Where c = s Select c).Count().ToString() & s
    Next
    Return result
End Function
  • Related