Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 25th, 2005, 2:41 PM   #1
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
any way to optimize this?

            fileformat = Replace(fileformat, "  ", " ") 'Catches double spaces
            fileformat = Replace(fileformat, " - - ", " - ") 'Reduces doubly-spaced hyphens
            fileformat = Replace(fileformat, "( )", "") 'Erases empty parentheses
            fileformat = Replace(fileformat, "[ ]", "") 'Erases empty brackets
            fileformat = Replace(fileformat, "()", "") 'Erases empty parentheses
            fileformat = Replace(fileformat, "[]", "") 'Erases empty brackets
            fileformat = Replace(fileformat, "{}", "") 'Erases empty squigglies
            fileformat = Replace(fileformat, "[ ", "[") 'Catches space after bracket
            fileformat = Replace(fileformat, " ]", "]") 'Catches space before bracket
            fileformat = Replace(fileformat, "( ", "(") 'Catches space after parenthesis
            fileformat = Replace(fileformat, " )", ")") 'Catches space before parenthesis
            fileformat = Replace(fileformat, " }", "}") 'Catches space before squiggly
            fileformat = Replace(fileformat, "{ ", "{") 'Catches space after squiggly
            fileformat = Replace(fileformat, " - .", ".") 'Catches ending hyphen/extension snares
            fileformat = Replace(fileformat, "-.", ".") 'Catches ending hyphen/extension snares
            fileformat = Replace(fileformat, " .", ".") 'Catches spacing before extension
            fileformat = Replace(fileformat, ". ", ".") 'Catches spacing after extension

just looking at all the repeated commands with slightly changed parameters irritates me. is there any way to optimize this?
chepfaust is offline   Reply With Quote
Old Mar 25th, 2005, 5:08 PM   #2
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
*head explodes* I don't think there is a way. Sorry. But you could ask someone like oobs or Pizentios.
__________________
And there was much rejoicing... Yay....
Cipher is offline   Reply With Quote
Old Mar 27th, 2005, 3:25 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
There definitely is!!! Look at the code! You are forcing VB to loop through a whole string about 15 different times, which makes the function really inefficient and slow. You should construct a for loop or something to parse the string in one rather than 15 passes, which will be significantly quicker.
Rory is offline   Reply With Quote
Old Mar 27th, 2005, 5:14 PM   #4
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by Rory
There definitely is!!! Look at the code! You are forcing VB to loop through a whole string about 15 different times, which makes the function really inefficient and slow. You should construct a for loop or something to parse the string in one rather than 15 passes, which will be significantly quicker.
i think i see what you're saying, but i'm really at a loss as to how i'd go about it (the parsing, not the loop itself). if i had any clue, i would have tried it already

Last edited by chepfaust; Mar 27th, 2005 at 5:50 PM.
chepfaust is offline   Reply With Quote
Old Mar 28th, 2005, 6:34 PM   #5
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Well one way is to loop through the whole string using mid to get the character at that position. Using a select case to see if it is a bracket, you should check the characters either side to make sure it is not a space. Secondly keep a "bracket count" to ensure the brackets come in pairs. Add one to it when you find "(", subtract one when you find ")". If the total is not zero at the end, there is an unclosed/unopened bracket somewhere.
Rory is offline   Reply With Quote
Old Mar 28th, 2005, 7:18 PM   #6
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
hah! i understand you now. i'll definitely do something with that; it makes a lot of sense. thanks!
chepfaust is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC