How many names are being processed? To determine exact timing
before these changes add
<%@ trace="true"%>
to file and run it a few times to get hard numbers on current speed.
Then make below changes and see how much faster it is.
Some suggestions:
1.
Your first loop is probably just better done with one line replace method.
2. A few of your Ifs will be more readable (and probably faster) as SELECT
CASE. Lets take one instance of your code =>
If cbo_routers.SelectedItem = "212.26.73.240" Then
str_pos = txt_router_main_2.Text.IndexOf("V", 0)
ElseIf cbo_routers.SelectedItem = "212.24.239.1" Then
str_pos = txt_router_main_2.Text.IndexOf("Asyn", 0)
ElseIf cbo_routers.SelectedItem = "212.26.73.61" Then
str_pos = txt_router_main_2.Text.IndexOf("V", 0)
ElseIf cbo_routers.Text = "212.26.73.1" Then
str_pos = txt_router_main_2.Text.IndexOf("V", 0)
ElseIf cbo_routers.Text = "212.26.73.111" Then
str_pos = txt_router_main_2.Text.IndexOf("V", 0)
End If
and replace with =>
Select Case cbo_routers.SelectedItem
Case "212.26.73.240","212.26.73.61","212.26.73.1","212.26.73.111"
str_pos = txt_router_main_2.Text.IndexOf("V", 0)
Case "212.24.239.1"
str_pos = txt_router_main_2.Text.IndexOf("Asyn", 0)
End Select
3. Second Loop you should use a string builder
above LOOP =>
dim sb1 as new string builder
inside LOOP =>
with sb1
.append (str_temp2)
.append (txt_router_main_2.Text.Chars(str_pos))
end with
outside LOOP =>
lst_all_users.Items.Add(Trim(sb1,ToString())
4. Property Reads are always expensive, minimize them for example
Your code =>
If Char.IsLetterOrDigit(txt_router_main_2.Text.Chars(str_pos)) = True _
Or txt_router_main_2.Text.Chars(str_pos) = "@" _
Or txt_router_main_2.Text.Chars(str_pos) = " " Then
If txt_router_main_2.Text.Chars(str_pos) = " " Then
should be this code =>
Dim onechar as string=txt_router_main_2.Text.Chars(str_pos)
If Char.IsLetterOrDigit(onechar) = True OR onechar = "@" OR onechar= " " Then
If onechar = " " Then
5.
Do the same thing for .Length and .text that you ue in your code. Reading a
popety only once is vital to achieving speed. Also look for other chances
to use StringBuilder.