Sorry for such a beginner's issue, but I just ran into a spot where wait key isn't working in a program. It's just being used to hold open the execution window and no key press will exit the program. I have to click on the X close and the program stays in memory. The only way I've been able to get rid of it is by killing the process.
Using Win7 64bit. DBPro 1.054
It's not overly important since this file will be used as an include, but annoying nonetheless.
Thanks!
`------------------------------------------------------------------
`String Functions from Chapter 8 of Hands on DarkBASIC Pro Volume 1
`------------------------------------------------------------------
`
`remstart ***test area***
cls
print "----Test----"
print
print "Pos(test,s)"
print Pos("test","s")
print
print "Occurs(test,t)"
print Occurs("test","t")
print
print "Insert$(test,er,5)"
print Insert$("test","er",5)
print
print "Delete$(test,2,2)"
print Delete$("test",2,2)
print
print "Replace$(test,T,1)"
print Replace$("test","T",1)
print
print "Copy$(test,2,3)"
print Copy$("test",2,3)
print
print "----Press any key to exit----"
wait key
end
`remend
`=====================================================================
`
`Pos() returns the position of a character in a string
function Pos(s$,c$)
`*** Result stays at -1 if no match found ***
Result = -1
`*** make sure we're looking for a single character ***
first$ = mid$(c$,1)
`
`*** FOR each character in s$ DO ***
for c = 1 to len(s$)
`*** IF that character matches what we're after THEN ***
if mid$(s$,c) = first$
`*** set Result to this position and exit loop ***
Result = c
exit
endif
next c
endfunction Result
`
`=====================================================================
`
`Occurs() returns how often a character appears within a string
function Occurs(s$,c$)
`*** none found so far ***
Result = 0
`
`*** make sure only one caracter ***
first$ = mid$(c$,1)
`
`*** FOR each character in s$ DO ***
for c = 1 to len(s$)
`*** IF it matches the required character add 1 to Result***
if mid$(s$,c) = first$
Result = Result + 1
endif
next c
endfunction Result
`
`=====================================================================
`
`Insert$() inserts one string into another
function Insert$(s1$,s2$,post)
`*** IF invalid position result$ is original string ***
if post < 1 or post > len(s1$)+1
result$ = s1$
else
`*** split s1$ into two parts and insert s2$ between them ***
result$ = left$(s1$,post-1)
result$ = result$ + s2$
result$ = result$ + right$(s1$,len(s1$)-(post-1))
endif
endfunction result$
`
`=====================================================================
`
`Delete$() removes a sections of a string
function Delete$(s$,start,num)
`*** IF invalid position, result$ is original string ***
if start < 1 or start > len(s$)
result$ = s$
else
`*** construct result$ from left and right of deleted part ***
result$ = left$(s$,start-1)
result$ = result$ + right$(s$,len(s$)-(start+num-1))
endif
endfunction result$
`
`=====================================================================
`
`Replace$() replaces a single character in a string
function Replace$(s$,c$,post)
`*** IF invalid position result is original string ***
if post < 1 or post > len(s$)
result$ = s$
else
`*** make sure only one character is being replaced ***
first$ = mid$(c$,1)
`***result is the original string with new character at post***
result$ = left$(s$,post-1) + first$ + right$(s$,len(s$)-post)
endif
endfunction result$
`
`=====================================================================
`
`Copy$() returns a copy of part of a string
function Copy$(s$, start, num)
`***IF invalid position result$ is empty ***
if start < 1 or start > len(s$)
result$ = ""
`*** set # of chars to return to be len(s$) or num ***
else
if start + num - 1 > len(s$)
lastPosition = len(s$)
else
lastPosition = start + num - 1
endif
for c = start to lastPosition
result$ = result$ + mid$(s$,c)
next c
endif
endfunction result$
`
`=====================================================================
~Aspiring~