Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Make all values in arrayist to titlecase+vb.net

Hello,

How can I make all values in arraylist to titlecase+vb.net desktop app

Cheers
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Hi,

Pls try..

Dim myList As New List(Of String)() From { _
             "Pawan", _
             "Pawan", _
             "PAWAN", _
             "pAWAAn" _
            }
        Dim currentCulture As CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture

        myList = myList.[Select](Function(r) currentCulture.TextInfo.ToTitleCase(r.ToLower())).ToList()

Open in new window

Avatar of RIAS

ASKER

trying
Avatar of RIAS

ASKER

pawan,
Error: Select is not a member of Arraylist
Can you pls post the entire code you are trying?
Avatar of RIAS

ASKER

Dim Arr1, Arr2, Arr3, Arr4 As New ArrayList
Arr1 = Arr1.[Select](Function(r) currentCulture.TextInfo.ToTitleCase(r.ToLower())).ToList()
I am using System.Collections.Generic.List..

can you use this?
Avatar of RIAS

ASKER

Can't change arraylist to System.Collections.Generic.List...
need to use arraylist
Try this to convert array to generic list..and then use the above code.

Pawan [] arr;
List<Pawan> list = arr.ToList();
Avatar of RIAS

ASKER

Can't understand what you are asking me to do .
Try this complete code..

        Dim s As String() = New String() {"Pawan", "Pawan", "Pawan", "PAWAN", "pAWAAn"}

        Dim myList As New List(Of String)(s)

        Dim currentCulture As CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture

        myList = myList.[Select](Function(r) currentCulture.TextInfo.ToTitleCase(r.ToLower())).ToList()

Open in new window


Output

User generated image
Hope it helps !!
Avatar of RIAS

ASKER

Nope pawan,
Please let me know how to do conversion in arraylist only.
Can;t change arraylist to something else.
Hi,
Please see the last comment.
Avatar of RIAS

ASKER

Thanks pawan,
Tried this

    Dim myList As New List(Of String)(Arr1)
                myList = myList.[Select](Function(r) currentCulture.TextInfo.ToTitleCase(r.ToLower())).ToList()

                SetCombobox(Cmbo1, Need Arraylistback here)
            

Open in new window


how to convert MyList to arraylist?
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

'Dim ArrList As New List(Of String)(Arr1)

Gave an error:
invalid cast expression
Avatar of RIAS

ASKER

Also I am using Arraylist and nor array :>
can you please post entire code?
Avatar of RIAS

ASKER

  Dim Arr1, Arr2, Arr3, Arr4 As New ArrayList

            Arr1.Add("")
            Arr2.Add("")
            Arr3.Add("")
            Arr4.Add("")
            Do While SQLdr.Read()
                If IsDBNull(SQLdr(StrCol1)) = False Then
                    StrColval1 = SQLdr(StrCol1).ToString
                    'StrColval1 = StrColval1.Replace(" ", String.Empty)

                    If StrColval1 <> String.Empty AndAlso StrCol1 <> "SentBy" Then
                        'Check for duplicates in array

                        If Not (Arr1.Contains(StrColval1)) AndAlso Not (Arr1.Contains(StrColval1.ToLower)) Then
                            If Not (Arr1.Contains(StrColval1.ToUpper)) Then
                                Arr1.Add(StrColval1.ToUpperInvariant)
                            End If
                        End If
                    ElseIf StrCol1 = "SentBy" Then
                        If Not (Arr1.Contains(StrColval1)) AndAlso Not (Arr1.Contains(StrColval1.ToLower)) Then
                            If Not (Arr1.Contains(StrColval1.ToUpper)) Then
                                If StrColval1.ToUpper = "M" OrElse StrColval1.ToUpper = "A" OrElse StrColval1.ToUpper = "jijJ" OrElse StrColval1.ToUpper = "Sii" Then
                                    Arr1.Add(StrColval1.ToUpper)
                                End If
                            End If
                        End If
                    End If
                End If

Open in new window

Not getting this looks like a separate code? Below is working for me.

Dim s As String() = New String() {"Pawan", "Pawan", "Pawan", "PAWAN", "pAWAAn"}
Dim myList As New List(Of String)(s)
Hi Rias,
Any luck ?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Thanks!
You could just do...
For i As Integer = 0 To Arr1.Count - 1
	Arr1(i) = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Arr1(i).ToString.ToLower)
Next

Open in new window