|
Joined: Jan 2006
Posts: 19
Pikka bird
|
OP
Pikka bird
Joined: Jan 2006
Posts: 19 |
how would i delete 1 word out of a txt document, in the same line
like blah.txt
aaa aaa2 aaa3 aaa4
and it deletes aaa2 or aaa3 when procedure is called for
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
This will remove every instance of the word from every line in the file, assuming your format is as described. If the word also contains punctuation then it won't be removed. Change what's in red. Useage: /removeword <word> alias removeword {
var %file = [color:red]yourfile.txt[/color]
window -h @removeword
loadbuf @removeword %file
var %i = 1, %c, %f, %r, %r2
while (%i <= $line(@removeword,0)) {
%c = $line(@removeword,%i)
if ($istok(%c,$1,32)) {
if ($findtok(%c,$1,0,32) > 1) {
%f = 1
while (%f <= $numtok(%c,32)) {
if ($gettok(%c,%f,32) != $1) { %r = %r $+ $chr(32) $+ $gettok(%c,%f,32) }
inc %f
}
write $+(-l,%i) %file %r
}
else {
%r2 = $deltok(%c,$findtok(%c,$1,1,32),32)
write $+(-l,%i) %file %r2
}
}
inc %i
}
window -c @removeword
}
|
|
|
|
Joined: Jan 2006
Posts: 19
Pikka bird
|
OP
Pikka bird
Joined: Jan 2006
Posts: 19 |
sorry didnt work, its for a bot im making that uses a nickname system it has like users=blah blah blah blah in a txt document
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Give this a try alias removeword {
var %line = 1, %file = [color:red] file.txt [/color] , %lines = $lines(%file), %read
while %a <= %b {
%read = $read(%file,ntw,$+(*, ,$1, ,*),%a)
%a = $readn
%read = $remove(%read,$1)
.write -l $+ %a %file %read
inc %a
}
}
Again, replace the file.txt with the name of your actual file. You might be smart to make a backup of the file, just in case.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
sorry didnt work, its for a bot im making that uses a nickname system it has like users=blah blah blah blah in a txt document If it's for a bot and in a different format than what you gave in the first post then don't expect a working code. There's no way I could have known that since you didn't give any real details. Also to RusselB, you never gave %a or %b a value  I chose not to do it that way due to the original post. If you issue "removeword ccc" and there is a line with "ccc ccc2 ccc3 ccc4" the line results in "2 3 4" when it should really be "ccc2 ccc3 ccc4". Of course that's just a silly example, but "ccc" could be part of another word in which case it shouldn't be removed.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
I plead lack of sleep for my defense of not switching all of the variables (I'd just finished a 10 hour work shift)
As to your second point...yeah...didn't think about that...I'll give this problem some more thought when I'm awake and post unless someone else beats me to it.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
You still dont really explain yourself.
So the file has multiple lines with user1=nick1 nick2 nick3 nick4 etc user2=nicka nickb nickc nickd etc etc
OR
it has one line with users=name1 name2 name3 name4
??????
since you asked to be able to remove A word from A line, and now we know the line is started with a "<field>=", here it is.
;$1 = file ;$2 = line ;$3 = word remove.word { var %line = $read($1,nt,$2) if (*=* iswm %line) { write -l $+ $2 $left(%line,$pos(%line,=,1)) $+ $remtok( $mid(%line,$calc($pos(%line,=,1) + 1)) ,$3,1,32) } }
|
|
|
|
Joined: Jan 2006
Posts: 19
Pikka bird
|
OP
Pikka bird
Joined: Jan 2006
Posts: 19 |
ok this is the format, when someone types `entered it will read from entered.txt when they type `enter it enters them and adds them to the .txt and when they type `leave it removes them from the txt heres the code
alias addenter { writeini entered.txt entered enter $readini(entered.txt,entered,enter) $nick }
on *:TEXT:`leave*:#:{ if ($readini(wars.ini,$nick,entrd) = no) { halt } else { msg # $skz($aura Has Left The Battle Field) writeini wars.ini $nick entrd no mode # -v $nick } }
on *:TEXT:`enter*:#:{ if ($readini(wars.ini,$nick,dead) = yes) { notice $nick 00You `heal first halt } if ($readini(wars.ini,$nick,entrd) = yes) { halt } else { msg # $skz($aura Has Entered The Battle Field) addenter writeini wars.ini $nick entrd yes mode # +v $nick } }
|
|
|
|
|