|
Post by DARKNIGHT on Jan 25, 2024 23:50:50 GMT -5
Hello All, I I know this seems Silly and trivial, but this is going to be used for another App that I am currently working on. I thought that using Left$ would work, but it seems like that is for display purposes only. here is my code, that I tried using for this purpose, but to no Avail.
let b$="/" let a$="1234/Test" for x=1 to len(a$) let f$=left$(a$,x) if f$=b$ then print "*" print f$ next x any suggestions of how I might facilitate this, would be greatly appreciated thank you in advance Jim
|
|
|
Post by tsh73 on Jan 26, 2024 1:11:53 GMT -5
Hello Jim single character from string is obtained via MID$ So here c$ is single charcter, and in IF we compare to it.
let b$="/" let a$="1234/Test" for x=1 to len(a$) let f$=left$(a$,x) let c$=mid$(a$,x,1) if c$=b$ then print "*" print f$ next x
1 12 123 1234 * 1234/ 1234/T 1234/Te 1234/Tes 1234/Test
|
|
|
Post by Carl Gundel on Jan 26, 2024 10:35:01 GMT -5
You can also use the instr() function to scan for one or more characters.
print instr("this is a test", "is") print instr("this is a test", "is", 1) 'starting at position 4 print instr("this is a test", "is", 4)
print searchMe$ = "This is a test. Give me a list of positions." searchFor$ = "is" print "Search for all '"; searchFor$; "' in '"; searchMe$; "'" pos = instr(searchMe$, searchFor$) if pos then print pos while pos pos = instr(searchMe$, searchFor$, pos + 1) if pos then print pos wend end if print "Done." end
|
|
|
Post by DARKNIGHT on Jan 26, 2024 13:53:50 GMT -5
Thank you tsh73 and Carl! now I can proceed with my program!
I will try both of these methods.
much appreciated!
it was a thrill to speak with you carl, I really love coding in Liberty basic. I started in Apple Basic back in 1984, in HS, on an Apple II E. once I learned all the commands, and started writing my own code, I was Hooked! still learning, through experimentation in Liberty Basic and with help from my friends here on the LB Community Forum.
|
|
|
Post by DARKNIGHT on Jan 26, 2024 19:08:14 GMT -5
o.k that worked Great! so Now, how would I use the code you posted to cycle through a text file and search for a whole word within the text file ?
as an example of my text file is formatted as thus:
Jones,Rob,R,2289 Smith, Alan,T, 4673 Wilks,John,K,8276
I am trying to create a program to search for Data within the file, using the code you posted. other then the usual method of:
[loop]' * Cycle data records
input #1, b$ if b$=a$ then goto [SubName] if eof(#1)=0 then [loop]
{with a$ as the search term}
I have tried several times myself, but no output to screen. . .
thanks Guys , you rock!
|
|
|
Post by Brandon Parker on Jan 26, 2024 21:39:34 GMT -5
Searching for data in a file is as easy as the code below. It is normally much faster to input everything in a file into a variable and search that variable.
'Data in file 'Don't forget there is a chr$(13) and chr$(10) 'at the end of each line
'Jones,Rob,R,2289 'Smith,Alan,T,4673 'Wilks,John,K,8276
findMe$ = "Alan"
Open "Your File Path Here\TestDocument.txt" For Input As #Test
var$ = Input$(#Test, LOF(#Test))
Print "Location of ";findMe$;" is: ";Instr(var$, findMe$)
Close #Test
{:0)
Brandon Parker
|
|
|
Post by DARKNIGHT on Jan 26, 2024 22:22:12 GMT -5
Wow! Thanks Man! I guess I was over complicating my code, and trying to do it the hard way.
I thought it would be more involved then this, You Rock!
|
|
|
Post by Carl Gundel on Jan 27, 2024 12:03:15 GMT -5
Thank you tsh73 and Carl! now I can proceed with my program!
I will try both of these methods.
much appreciated!
it was a thrill to speak with you carl, I really love coding in Liberty basic. I started in Apple Basic back in 1984, in HS, on an Apple II E. once I learned all the commands, and started writing my own code, I was Hooked! still learning, through experimentation in Liberty Basic and with help from my friends here on the LB Community Forum.
Hey Jim, the pleasure is mine! I also programmed Apple II computers back in 1980s. That was my first actual programming job. Fun times.
|
|