Hi,
How can i can in a text file on every word the last two numbers or remove then.
Pam
Assuming you consider a "word" to be group of characters separated from other groups by a SPACE, I would retrieve the contents and then a FOR Loop to loop through the words doing what I want with them.
Some functions of interest would be FileGet(), StrReplace(), ItemExtract() and a few others. Should be a fairly simple operation.
Jim
look easy but not for me.
I have words and a want to remove in a file the last two numbers on the end.
beef01
beef045
horse23
pam
If you post an sample file someone may be willing to post some code that might ease your way into a solution.
Jim
Quote from: pamsniffer on March 22, 2015, 09:19:58 AM
look easy but not for me.
I have words and a want to remove in a file the last two numbers on the end.
beef01
beef045
horse23
pam
last 2 - so beef01 becomes beef and beef045 becomes beef0
Be sure what you are asking for.
You may need to do a bit of tweaking but something like the following should work. It could be shortened but I went the long route for readability.
old_file = "c:\......"
new_file = "c:\....."
txt = FileGet(old_file)
txt = StrReplace(txt,@CRLF,@CR)
cnt = ItemCount(txt,@CR)
nlist = ""
For x = 1 to cnt
line = ItemExtract(x,txt,@CR)
line = StrTrim(line)
line = StrSub(line,1,StrLen(line)-2)
nlist = nlist:line:@CR
Next
FilePut(new_file,nlist)