Code archives/File Utilities/Simple way to separete/cut a string
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
I use this little function to load my map files that are stored on a simple text file. You can store some stuff like this : "info1/info2/info3/" | |||||
Cuts the string and gets only the info you want Ex: If CString$ is "abc/def/" and CNumber if 2, then the function will return "def". * DO NOT FORGET TO INCLUDE A "/" IN THE END OF THE STRING * This little function was made by Insane Games (david@infomaniacos.org). If you know how to make it goes faster or how to avoid the use of the last "/", please, send me an email. Thanx. Function CutString$(CString$, CNumber) stemp$ = "" numtemp = 0 For temp=1 To Len(CString$) If Mid(CString$, temp, 1)<>"/" stemp$ = stemp$ + Mid(CString$, temp, 1) Else numtemp = numtemp + 1 If numtemp = CNumber Return stemp$ Else stemp$ = "" EndIf EndIf Next Return "" End Function ;Print CutString$("abc/def/", 2) ;- just for testing |
Comments
| ||
or how to avoid the use of the last "/" Inside the function, before the processing, check the most-right character of the input string. If it's a "/".. do nothing .. If it's not a "/": CString$=CString$+"/" :) |
Code Archives Forum