| View previous topic :: View next topic |
| Author |
Message |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 13, 2004 10:00 pm Post subject: Finding second occurance of charactors postion |
|
|
Anyone know how to find the second occurance postion number of a charactor in a text file.
I can get the first one ok, but having trouble getting the seconds number position in the file or @TEXT(1).
| Code: |
LIST CREATE,1
LIST loadfile,1,c:\example.txt
%m = @POS(.,@text(1))
info %m
LIST CLOSE,1
|
Above gets the first position(12), but I need to get the next (period), not the first one.
Second is approximatly charactor position(56).
I can also get to the 1st one with %match(1), but couldn't get the charactor position use the @STRINS() function. (I'm trying to replace a filename that lengh and name is different each time in different text files.) |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1566
|
Posted: Fri Feb 13, 2004 10:09 pm Post subject: |
|
|
| What you need to do is delete the first period character from the string you are searching from. You can do that with @strdel function. Then do another search for the character using @pos. Delete the characters each time after you find them and you will be able to find all occurances of the character. |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 13, 2004 10:33 pm Post subject: |
|
|
I figured I'd have to do it that way, guess thats the only way, maybe VDS will make a new function in the next release @skip() lol
Thanks anyways.. |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Feb 13, 2004 10:35 pm Post subject: |
|
|
can i suggest an alternative...
it will take more coding but it will avoid having to delete anything from your string
i am writing this code off the top of my head so excuse any mistakes...the idea is to go through each character in your string to see if it is a full stop or not
i am assuming that you want to process %%string
| Code: |
%i = 1
repeat
%%dummy = @substr(%%string,%i,%i)
if @equal(%%dummy,.)
info Position %i contains a .!
end
%i = @succ(%i)
until @equal(%i,@len(%%string))
|
you will need to code in a check to make sure that %%string is at least 1 character long for this to work or you will get an error
serge _________________
|
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Feb 13, 2004 10:43 pm Post subject: |
|
|
You can also just copy the original string to a tmp
string, then use @pos() and @strdel() on it instead
of the original...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 13, 2004 10:44 pm Post subject: |
|
|
By golly that looks like it'll work Serge, thanks for the real bullets.
The file is quite long (40394 charactors 1.83 MB) Hopefully it wont be slow or laggysearching for the .
REPEAT seems like the anwser...thanks again |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Feb 13, 2004 11:06 pm Post subject: |
|
|
glad to help vtol777
if it takes too long using my code...try pg and mac's idea combined
serge _________________
|
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Fri Feb 13, 2004 11:17 pm Post subject: |
|
|
hee hee
yeah, its still searching using 99% of my system resources, I'll just TEMP string delete it and add 1.
I should have explained it was a huge text file, sorry..
But I will enjoy your little dummy REPEATer a lot in the future on small strings - etc, thanks again Serge. |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Feb 13, 2004 11:33 pm Post subject: |
|
|
glad to help...i use %%dummy a lot when i have to deal with temporary variables ie variables used only within a subroutine as it saves me having to come up with new names + it cuts down on the amount of memory used by my program as i recycle the same variable
serge _________________
|
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Sat Feb 14, 2004 12:24 am Post subject: |
|
|
This seems to work great till it gets in the 60's area, then every charactor reads as a .
Is there a way to make the REPEAT not see the minus sign, or is it something else goofing it up?
| Code: | %t = DataSet vvv . eds GrdLand { Version 4 3DPosition -7296.000000 768.000000 15360.000000 3DRotation 82.000000 0.000000 0.000000
%c = 1
%i = 1
repeat
%c =@SUM(%c,1)
%%dummy = @substr(%t,%i,%i)
if @equal(%%dummy,.)
info Period is here %i
end
%i = @succ(%i)
until @equal(%c,139) |
I took your Idea and kinda modified it since my second period is within the first 500 charctors Serge... |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sat Feb 14, 2004 12:41 am Post subject: |
|
|
interesting problem...the minus does not seem to be the problem as i removed it and still got errors
i amended your code to the following
| Code: |
%t = DataSet vvv . eds GrdLand { Version 4 3DPosition -7296.000000 768.000000 15360.000000 3DRotation 82.000000 0.000000 0.000000
%c = 1
%i = 1
repeat
%c =@SUM(%c,1)
%%dummy = @substr(%t,%i,%i)
if @equal(%%dummy,.)
info Period is here %i<>%%dummy
end
%i = @succ(%i)
until @equal(%c,139) |
and found that zeroes returned a positive match as well as full stops
perhaps pg and mac's idea will be better...although will they yield a positive match on the zeroes too
i'll think about it today and let you know if i come up with something unless somebody else finds out what is ging on first
serge _________________
|
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sat Feb 14, 2004 12:48 am Post subject: |
|
|
found an answer for you...no idea why this way works but sometimes a different way of doing something works...ggrr!!!
| Code: |
%t = DataSet vvv . eds GrdLand { Version 4 3DPosition -7296.000000 768.000000 15360.000000 3DRotation 82.000000 0.000000 0.000000
%c = 1
%i = 1
repeat
%c =@SUM(%c,1)
%%dummy = @substr(%t,%i,%i)
if @equal(@asc(%%dummy),46)
info Period is here %i
end
%i = @succ(%i)
until @equal(%c,139)
|
note that the program does not close graciously at the end
serge
ps won't be online now as i have to go out...will check your replies later on _________________
|
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sat Feb 14, 2004 12:50 am Post subject: |
|
|
i'm on a roll here...fixed the not so gracious exit at the end of the program
| Code: |
%t = DataSet vvv . eds GrdLand { Version 4 3DPosition -7296.000000 768.000000 15360.000000 3DRotation 82.000000 0.000000 0.000000
%c = 1
%i = 1
repeat
%c =@SUM(%c,1)
%%dummy = @substr(%t,%i,%i)
if @equal(@asc(%%dummy),46)
info Period is here %i
end
%i = @succ(%i)
until @equal(%c,@len(%t))
|
now it exits nicely...but you need to consider the case where the last entry is a .! _________________
|
|
| Back to top |
|
 |
vtol Valued Contributor


Joined: 05 Feb 2004 Posts: 656 Location: Eastern Indiana
|
Posted: Sat Feb 14, 2004 1:03 am Post subject: |
|
|
Nice, I was wondering about @asc, but would have just searched with chr code prolly, I like the way you did it much better, kinda NASA like, lol..
Thanks, really appreciate it.
In the mean time I found if I search for the '{' charactor I dont have to use @asc and I only run into 2 of those before I get to the filename I'm trying to replace. (Its a Map File Editing Utility I'm making for my favorite War Game - It will do all the file Edits with out the person having to learn to use a Text editor, plus automates other things.FreeSoftware)
And it seems I run into all the weird odd problems as I try harder, lol.. |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sat Feb 14, 2004 7:42 am Post subject: |
|
|
i tried to use @equal(%%dummy,@chr(46)) but that didn't work either...no idea why...so i tried the method i showed you
glad to help
serge _________________
|
|
| Back to top |
|
 |
|