Hello, dead all!
How can I search and replace a string in a file (text file)? I want to have a function to handle that. I can use SHELL with sed but I don't consider that better than using Gambas for that. I can search in the file with the following function:
PUBLIC FUNCTION Get_Str(tmpFile AS String, tmpStr AS String) AS Variant
DIM sLine, Result AS String
DIM hFile AS File
hFile = OPEN tmpFile FOR INPUT
WHILE NOT Eof(hFile)
LINE INPUT #hFile, sLine
IF sLine LIKE "*" & tmpStr & "*" THEN
sLine = Replace$(sLine, "\"", "")
sLine = Replace$(sLine, "export ", "")
Result = Replace$(sLine, tmpStr, "")
BREAK
ENDIF
WEND
RETURN Result
CATCH
Message.Error("Unable to get info!\n\nFile: " & tmpFile & "\nString: " & tmpStr)
END
But how about replacing strings? I'm not an expert so a few lines of comments will be helpful too.
Thanks in advance!
PS: This is just a function from my applications