mIRC Home    About    Download    Register    News    Help

Print Thread
#117362 14/04/05 11:57 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Would be nice is $mid was extended to become this

$mid original

$mid(text,S,N)
Returns N characters starting at position S in text.
$mid(othello,3,4) returns hell
If N is zero, it returns the number of characters from S to the end of the line.
You may also use negative numbers for S or N.

or newstuff

$mid(text,S,N,newtext)
Returns text with N characters starting at position S in text replaced with newtext
$mid(SampleWordsHere,7,4,Textz) returns SampleTextHere
If N is zero no text is replaced


* The below bits a fiddly but could be worked out.
maybe if if N is negitive it takes it from the right of newtext, but inserts it the right way smile
N is greater than len of newtext, ummm newtext repeats? or extras N values ignored or extra characters removed, I dont know i could live with any of them
might be some other things to think about

This was a functionality of the MID function right back in old BASIC days, dont see that it would effect anything here as currently a 4th parameter well cause
* Invalid parameters: $mid
so any new usage wouldnt cross the old stuff.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
It wouldn't be all that much different from using a combination of $replace and $mid, but it would make it easier and more efficient.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Yeah its not like i cant do it manually, but it wouldnt conflict (i assume) and is a part of the mid functionality on other platforms.

Joined: Oct 2003
Posts: 5
S
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
S
Joined: Oct 2003
Posts: 5
I actually think that having a /mid alias, as in, not an identifier, is much more in the spirit of how mIRC works.
Code:
/mid some_text 3 2 w00t
could return "sow00t_text", as in, replace 2 characters, starting from the 3rd character, with "w00t". This means that it would be equivilant to:
Code:
/return $left($1,$calc($2 - 1)) $+ $4- $+ $right($1,$calc($2 + $3 - 1))
(this code may be inaccurate.)

Notice that the length of the new piece of string does not have to be equal to the length of the substring replaced.


Best Regards,
seec77
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
How exactly would a command return something? OK so there's $result, but why add an extra line to the code? Also it would create major limitations since only the final parameter of any command can contain an arbitrary number of spaces.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I'd like such a feature a lot, but probably as a separate identifier, like $replacepos(string,sub,N,M) or maybe a less wordy name. First because I'm rather not used to the idea of a mirc identifier that alters its behaviour 'drastically' just by specifying an extra param ($findfile() is a different story). Second because I'd prefer the params order I showed above. The main reason is that in $mid() you can omit the 3rd param; if $mid() were to get that extra <sub> param, you'd lose that ability, unless it accepted null params, like $mid(something,5,,body) (which it doesn't atm, $mid(abc,2,) returns $null).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Quote:
The main reason is that in $mid() you can omit the 3rd param; if $mid() were to get that extra <sub> param, you'd lose that ability, unless it accepted null params, like $mid(something,5,,body) (which it doesn't atm, $mid(abc,2,) returns $null).


I've never actually tried anything like that before so I never noticed it does that.
I think that (Where applicable) a null parameter should refer to the length of the first parameter, eg: $left($1,) = $1, $right($1,) = $1, $mid($1,2,) = $mid($1,2)


New username: hixxy
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I didnt really have a concern if it was in the $mid or another function, just if it could be included, I said $mid because thats what i rember it in. smile


Link Copied to Clipboard