January 26, 2021, 06:07:58 AM

Author Topic: [bmx] LtoRLook() by Zenn Lee [ 1+ years ago ]  (Read 406 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] LtoRLook() by Zenn Lee [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : LtoRLook()
Author : Zenn Lee
Posted : 1+ years ago

Description : If you are trying to add more than 1 file into a directory, while using RequestFile(), use this function to move up to the last "" from right.

You enter the string you want to search and then you enter the char. you want to end at.
Lets say you have this string "C:Documents and SettingsAdministratorfile.txt" and you want to add another file into the dir. above. You can use LtoRLook() to cut "C:Documents and SettingsAdministratorfile.txt" to "C:Documents and SettingsAdministrator"

Example: Lets say you want to save a .wav with the name returned by RequestFile() but you also wanted to save a .exe in that same directory.

Global File$ = ""
File$ = RequestFile("Save File","Wave Files:wav;",True)
CopyFile("Sound.wav",File$)
CopyFile("file2.exe",LtoRLook(File$,"") + File2 +".exe")

I know this function is simple but it has come in handy many times.


Code :
Code: BlitzMax
  1. Function LtoRLook:String(Str$,Char$)
  2.  L = Len(Str$)
  3.  While Not L = 0
  4.   L = L - 1
  5.   ReturnStr$ = Left(Str$,L)
  6.   If Mid(ReturnStr$,L,1) = Char$
  7.    Return ReturnStr$
  8.    L = 0
  9.   End If
  10.  Wend
  11. End Function


Comments :


Brucey(Posted 1+ years ago)

 Although for files, it might be easier to use :
Code: [Select]
dir$ = ExtractDir(file$):o)


Zenn Lee(Posted 1+ years ago)

 oh?! [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal