how can i keep the first word in a textbox and delete all other words
then search a .txt file for that word
if found add "*" befor it
simple but how? :confused:
Printable View
how can i keep the first word in a textbox and delete all other words
then search a .txt file for that word
if found add "*" befor it
simple but how? :confused:
Here's one way of doing it using the Replace() function.
VB Code:
Option Explicit Private Sub ReplaceInFile(ByVal FilePath As String, _ ByVal ReplaceThis As String, ByVal WithThis As String, _ Optional ByVal CompareMethod As VbCompareMethod = vbTextCompare) Dim strData As String, lonFF As Long Dim strPath As String 'Get available file handle. lonFF = FreeFile 'Open file. Open FilePath For Input As #lonFF 'Load all contents of file into strData. strData = Input(LOF(lonFF), lonFF) Close #lonFF 'Close file. 'Replace the words. strData = Replace$(strData, ReplaceThis, WithThis, , , CompareMethod) lonFF = FreeFile 'Create a 2nd file. strPath = FilePath & "(2).txt" Open strPath For Binary Access Write As #lonFF Put #lonFF, , strData Close #lonFF End Sub 'Test the code. Private Sub Command1_Click() 'Keep first word. Text1.Text = Left$(Text1.Text, (InStr(1, Text1.Text, " ") - 1)) 'Replace all words. 'vbTextCompare so it's not case-sensitive. ReplaceInFile "C:\file.txt", "word1", "*word1", vbTextCompare End Sub
Maybe you could do:
VB Code:
Private Sub Command1_Click() Dim strTempArray() As String Dim strTemp As String Dim intFreeFileNum As Integer Dim intCounter As Integer intFreeFileNum = FreeFile() strTempArray = Split(Text1.Text, " ") Text2.Text = strTempArray(0) Open "\filenamehere.txt" For Input As intFreeFileNum Do Until EOF(intFreeFileNum) Input #intFreeFileNum, strTemp strTempArray = Split(strTemp, " ") For intCounter = 1 To UBound(strTempArray) If LCase(Text2.Text) = LCase(strTempArray(intCounter)) Then Text2.Text = "*" + Text2.Text End If Next intCounter Loop Close intFreeFileNum End Sub
I think that does what you want to do without needing API.
i tried both ways but
i didn't got the star char in the file
why?
is the word in the textbox likely to be unicode?