Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

String Parsing Algorithm Pls

  Asked By: Annie    Date: Jul 06    Category: Asp.net    Views: 1396
  

Below is the *s I have shown output from a router. I have this output stored in
a string variable. I need to parse this string in a way that I can have only the
username as:
dream407454
dream402961
stored in a list box one by one.

I have want to dicard any think like space " " or @.. just the username, I have
a algorithm which is doing this but for long lists it tales at times upto 3 to 4
minutes, can someone please develop some algorith I mean could code to help me


User Access Verification

Username: usman
Password:

Dream-L2TP>terminal length 0
Dream-L2TP>show users wide
Line User
*130 vty 0 usman
Vi1 dream407454 @dream.com.sa
Vi2 dream4055@...
Vi4 dream402961
Vi5 dream2362
Vi7 dream5336
Vi10 dream4970
Vi11 dream6790
Vi13 dream7307
Vi15 dream6419
Vi16 dream7199
Vi18 dream402262
Vi19 dream11601
Dream-L2TP>

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Whitney Cruz     Answered On: Jul 06

Show us current code. I know lots of ways to speed up code.

 
Answer #2    Answered By: Maliha Malik     Answered On: Jul 06

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.

 
Answer #3    Answered By: Edward Jones     Answered On: Jul 06

I will implement the changes and will inform you
about how didi it affect.

 
Answer #4    Answered By: Lewis Welch     Answered On: Jul 06

I am not familiar with <%@ trace="true"%> thing, can u please tell me a
little more about it that do I mention it in webconfig and how do I note time,
reply whenever u have some free time.

 
Answer #5    Answered By: Mike Stephens     Answered On: Jul 06

http://www.learnasp.com/freebook/learn/debug2.aspx
shows typical use of trace. No web.config involved.

when you run the sample @
www.learnasp.com/.../sqlclientdropdown.aspx
look closely the the "Trace Information" table.

The last row "End Render" left column labelled "From First(s)"
tells how long  the page took to execute.

Notice also that right column shows time between last trace point.

The beauty is unlike response.write you don't have to comment out after
finished debugging..
<%@ trace="false"%>
turns off all of this
=> without having to remove the trace statements from your code  <=

http://www.learnasp.com/freebook/learn/debug1.aspx
shows way to use in web.config that is totally optional.

 
Answer #6    Answered By: Adalric Fischer     Answered On: Jul 06

Thanks, this is equally applicable for vb.net windows based application too?

 
Answer #7    Answered By: Julia Flores     Answered On: Jul 06
 
Answer #8    Answered By: Jarvia Miller     Answered On: Jul 06

Ok let me tell you how did it go.

I, as u mentioned first tried to avoid the call to object properties and tried
to minimize it as much as possible, this brought the processing time down from
2.5 minutes to almost a minute, but still there was one text box  having the
router output  I was constantly reading until the textbox.length.
Ok at this point I tried to findout about the string  builders and downloaded a
sample about it, implemented that and u know what is the processing time now?
guess!! 45 sec No, 30 No 10 No, it's less than or almost 1 Second, so what was
being done in 3 Minutes has now been achieved in 1 Sec, ALHAMDOLILAH that a help
from u came to me so useful that this application is again having interest for
all, as earlier due to manipulation time people were a bit reluctant.


 
Didn't find what you were looking for? Find more on String Parsing Algorithm Pls Or get search suggestion and latest updates.




Tagged: