![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
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 extensionjust looking at all the repeated commands with slightly changed parameters irritates me. is there any way to optimize this? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
*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.... |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#4 | |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
Quote:
![]() Last edited by chepfaust; Mar 27th, 2005 at 5:50 PM. |
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
hah! i understand you now. i'll definitely do something with that; it makes a lot of sense. thanks!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|