mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 8
E
Ex3 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Feb 2003
Posts: 8
I got two questions about reading text from a file:
First question: I have a line of text that includes   word from time to time.
How can I cut the text that comes before that word?
(Or how can I delete it, and break the line where it was?)
Maybe by using $regsub or something like that?

Second question: I have a text file and I want to read specific line of text out of there, but the text is written backwards... How can I read the text backwards in order for it to show normaly?

Third question: How can I scan the text file I have and to remove text in brackets including the brackets?

Thanks in advance.

Last edited by Ex3; 26/02/03 07:40 PM.
Joined: Feb 2003
Posts: 9
A
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
A
Joined: Feb 2003
Posts: 9
1st:
Seems easyer to replace   with some bogus char ... like ƒ ... and then use the TOKEN identifiers to grab what you want from the text...

$gettok($replace(Text with some   and some   la la, ,ƒ),1,131) = Text with some


---
as for 2 and 3:
Looping $read(..) useing $lines(..) shoudln't be that hard..

Joined: Dec 2002
Posts: 208
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 208
k, first question was answered prity well

so i'll skip down to the next 2.

first by 'brackets' i'm just going to asume because you rfirst question included '&nbsp;' that your probly reading in html .. so by brackets i'm asuming you mean < > (although they are NOT brackets)

heres a lil identifer i made a long time back that will strip them out of a given string ($1-) .. all u'd have to do is loop though the file and filter each line with it, perhaps writeing a new .tmp file at the same time

Code:
html.strip {
  var %ctr = 0, %tot = $numtok($1-,$asc(&lt;)), %str = $1-
  while (%ctr &lt; %tot) {
    inc %ctr | var %str = $+($gettok(%str,1,$asc(&lt;)),$gettok(%str,2-,$asc(&gt;)))
  }
  return %str
}


basicly what we are doing here is defining our loop, ctr is our counter, tot is how many tags need removed based on the number of tokens useing < as the deliminator chr, and defining %str to our current string, then what we do is we remove the first <tag> and reset the varable, and the next time we remove the first tag again (which beings the first was taken out is now the 2nd, but first in the new string) .. to do this is easy, take everythign before the first < and $+ it to everythign after the first >. (odds are this could be done easier with regex, but i dont do regex :P

hope that helps .. i left $asc() in there instead of useing the ascii values that way if u ment [ ] brackets or { } brases .. u can just change the chrs and it will work for those also.

i'll asume u know how to loop though the lines of a file .. so i wont bother writeing that part for you .. however if u need more help ask...

as far as your other question, taking text thats backwords and re-orderig it to be read normaly is quite simple, just lop though each chr useing $mid() and re-write the string like so.

Code:
str.reverse {
  var %ctr = 0, %tot = $len($1-), %str
  while (%ctr &lt; %tot) {
    inc %ctr | var %str = $mid($1-,%ctr,1) $+ %str
  }
  return %str
}


basicly we define a counter (ctr = 0) a total, (length of string), and then define the var we want to store the new string into. .. then its just a mater of looping though, building the var, and then returning it

Cobra^


Link Copied to Clipboard