| View previous topic :: View next topic |
| Author |
Message |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 6:27 am Post subject: search and replace problem |
|
|
hello all
ok lets say i have a txt file called test.txt and in this file i have this in there:
tim.txt - 1111 2222 3333 4444 5555 6666 7777 8888 9999
i want the tim.txt - chnage to tim-del: and i want the info that is after the - to stay there and not chnage.. so it would look like this in the txt file
tim.del : 1111 2222 3333 4444 5555 6666 7777 8888 9999
note: ANY data after the : can be alot like you see above or it could just have this in it 1111..so what i'am saying it can vary...
here is what i have for code but it don't work right what i'am doing wrong?
| Code: |
List Create,5
List Loadfile,5,"test.txt"
%N = "tim.TXT-"
%R = "tim-del:"
%M = @match(5,%N)
If %M
%C =@item(5),@len(@item(5)))
List Put,5,%R %c
info %r %c
list save,5,"test1.txt"
|
thanks _________________ Have a nice day  |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Mar 21, 2003 6:43 am Post subject: |
|
|
There are several threads on string find and replace. Try this one:
http://www.vdsworld.com/forum/viewtopic.php?t=690
and you really should try searching the forum before posting your questions.
You'd be surprised the answers you'll find.  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 6:55 am Post subject: i did |
|
|
i did search the forum BUT some of that code i saw i thought was to much for a easy task..meaning that there has to be a easyier way..to do it i thought  _________________ Have a nice day  |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 6:57 am Post subject: also |
|
|
If you look REALLY close at my code you will see that part of it DID come from a old thread  _________________ Have a nice day  |
|
| Back to top |
|
 |
Rubes_sw Valued Contributor


Joined: 11 Jun 2001 Posts: 625 Location: Northern Ireland
|
Posted: Fri Mar 21, 2003 7:08 am Post subject: |
|
|
You could use tommys vdsdll3.dll
@DLL(STRING, REPLACE, < string>, <search string>, <replace string>{, exact})
Replaces all instances of <search string> in <string> with <replace string>. Only if exact is provided, replacing is case sensitive.
I have used it, its fast, easy and reliable !
Nathan |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 7:10 am Post subject: hummmm |
|
|
hummm
ok but will that keep the other data intack? cuase that is the problem i'am haing now it cuts off some of the data or some of the data is missing
thanks _________________ Have a nice day  |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Mar 21, 2003 7:12 am Post subject: |
|
|
Ok. I'm not gonna fix your code for ya, but I will tell ya what I see is wrong
with it. Please don't take this wrong, but you gotta learn to do these things
yourself or you will never learn it.
First problem:
| Code: |
%C =@item(5),@len(@item(5)))
|
should be :
| Code: |
%C = @substr(@item(5),@pos(%N,@item(5)),@sum(@pos(%N,@item(5)),8))
|
And this line:
| Code: |
list save,5,"test1.txt"
|
should be:
| Code: |
list savefile,5,"test1.txt"
|
_________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 7:21 am Post subject: hummm |
|
|
ok
I see that you have
| Code: |
list savefile,5,"test1.txt"
|
even tho my was wrong it still saved the file tho..why didn't i get a error on that?
and this part
| Code: |
%C = @substr(@item(5),@pos(%N,@item(5)),@sum(@pos(%N,@item(5)),8))
|
can you explain what this is doing? I know it substractiing,etc BUT it would help me to have it explained cuase math is not my best area
thanks _________________ Have a nice day  |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 7:32 am Post subject: and |
|
|
mac- i did take a look at that thread ANd your code does look nice but i was trying to make a easy version that i can follow and understand better..i guess i should have listerned better when i was in math class back when i was young...and spelling class also...
 _________________ Have a nice day  |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Mar 21, 2003 7:34 am Post subject: |
|
|
Ok, let's see:
| Code: |
%C = @substr(@item(5),@pos(%N,@item(5)),@sum(@pos(%N,@item(5)),8))
|
| Code: |
@substr() is used to retrieve a string from within a string.
@item(5) is the text in the list where the index pointer is.
@pos(%N,@item(5)) returns the starting position of %N in the string @item(5)
@sum(@pos(%N,@item(5)),8) is adding the first found position of %N with
the length of %N which happens to be 8.
|
Another way to do this and maybe a little easier for you to see what is
happening would be like this:
| Code: |
%%first = @pos(%N,@item(5))
%%last = @sum(%%first,8)
%C = @substr(@item(5),%%first,%%last)
|
Does that help?  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 7:38 am Post subject: hummm |
|
|
that help some i don't get where did that 8 come from??? why 8?
thanks _________________ Have a nice day  |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Mar 21, 2003 7:40 am Post subject: |
|
|
The 8 comes from the length of %N. %N is 8 characters long. _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
tim6389 Professional Member


Joined: 01 Aug 2002 Posts: 790
|
Posted: Fri Mar 21, 2003 7:42 am Post subject: |
|
|
ahhhhh ok i see that..ok ok i understand that...i still trying to follow the rest..man i wish i could "see" this like you guys do  _________________ Have a nice day  |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Mar 21, 2003 7:45 am Post subject: |
|
|
It takes time Tim, unfortunately it doesn't happen overnight and it takes
longer for some people than it does for others. Just keep trying and you'll
figure it out one of these days.  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
|