I hate to burst your bubble, but "INSTR" is a function that deals with this. But good thinking though... :)
Code archives/Miscellaneous/Substring$(string1$,x,y)
This code has been declared by its author to be Public Domain code.
Download source code
| Zach3D (Zach J. meier) I wrote this because i use it alot and I think other people could use it(Please post your comments!) |
;Substring Function(gets the string located at A,B of string) Function Substring$(s1$,a,b) length = b - a J$ = Mid$(s1$,a,length + 1) Return J$ End Function trigstring$ = "Hello my name is Zach" Print SubString$(trigstring$,3,8) WaitKey() ;This prints "llo my" |
Comments
Instr doesn't do this, Instr finds one string in another.
He's right you know, Instr doesn't do this.
but I think mid$ might.
but I think mid$ might.
mid$(string$,3,5)
The issue is whether you want "startposition - end position" or "startposition - amount", that function does the first, mid$ does the second..
The issue is whether you want "startposition - end position" or "startposition - amount", that function does the first, mid$ does the second..
Exactly.
It's a simple function, but it makes working with strings appear much nicer.
Whenever I do stuff with strings, it ends up looking really confusing and messy because of things like Mid(string$,start,(end-start)+1)
It's a simple function, but it makes working with strings appear much nicer.
Whenever I do stuff with strings, it ends up looking really confusing and messy because of things like Mid(string$,start,(end-start)+1)
Only nitpick I could mention is the x,y .. typically you'd see those vars for anything 2d'ish, while this thing here reads from a 1d string. I'd avoid x,y and use x1,x2 or a,b or start,end etc.