Extract words from strings?
Blitz3D Forums/Blitz3D Programming/Extract words from strings?
| ||
patch$: = "C:\Maps\LevelMap.map" How can I extract the last word LevelMap.map, so that it is stored in a variable? print map$ ; Text on screen LevelMap.map |
| ||
Search for the last Backslash and use this position to cut the string:Print Filename("C:\Maps\LevelMap.map") Function FileName$(Path$) Local Where%=LastInstr(Path,"\") Return Mid(Path,Where,999) End Function Function LastInstr%(Txt$, Search$) Local Where%, Here% Repeat Where=Here+1 Here= Instr(Txt, Search, Where) Until Here=0 Return Where End Function |
| ||
@Midimaster Thanks You. :) |
| ||
You'd better reverse the string instead of using the InStr function.; returns "0" if not found Function FindLast%(s$, find$) For i = Len(s) To 1 Step -1 If Mid(s, i,1)=find Then Return i Next Return 0 End Function Local path$ = "C:\Maps\LevelMap.map" Print Right( path, Len(path) - FindLast(path, "\" ) ) (untested, but it should work I suppose) |