mIRC Homepage
Posted By: Sir_Cheer Trying to find specific text - 04/06/23 10:11 AM
I am trying to find specific text and texts that comes before or after it. Ill give an example


Suppose I have a string of text that says: AnApplicationCanBeUsedToFindContinuationOfData

Suppose I want to find characters after the words "CanBe"

Example:

$something(AnApplicationCanBeUsedToFindContinuationOfData,CanBe,1,4)

This would return "Used" because there is only 1 (second paramter) instance of CanBe in the string and 4 letters after it is Used.

$something(AnApplicationCanBeUsedToFindContinuationOfData,tion,2,5) would return OfDat because 5 character after the 2nd instance of tion would be OfDat

$something(AnApplicationCanBeUsedToFindContinuationOfData,tion,2,-5) would return tinua because 5 character before the 2nd instance of tion would be tinua and 5 is negative.

Does anyone know how to write a script that does this? I cant seem to get anything like this to work. Help???
Posted By: Epic Re: Trying to find specific text - 04/06/23 02:55 PM
Try use this script code that creates the identifier "$fsub" you need:
Code
alias fsub {
  if ($4 isnum && $3 isnum && $3 > 0 && $3 <= $pos($1,$2,0)) {
    if ($4 > 0) var %pos $calc($pos($1,$2,$3) + $len($2))
    if ($4 < 0) var %p $pos($1,$2,$3), %pos $calc(%p $4)
    if (%p && %pos < 1) return $left($1,$calc(%p -1))
    if (%pos <= $len($1)) return $mid($1,%pos,$abs($4))
  } | return 0
}

Syntax: $fsub(string, substring, index N, letters N)

Example: $fsub(helloworld, llo, 1, 5)

Test commands:
Code
//echo -a $fsub(AnApplicationCanBeUsedToFindContinuationOfData,CanBe,1,4)
//echo -a $fsub(AnApplicationCanBeUsedToFindContinuationOfData,tion,2,5)
//echo -a $fsub(AnApplicationCanBeUsedToFindContinuationOfData,tion,2,-5)

Returns:

  1. Used
  2. OfDat
  3. tinua



Note: In all other cases, when incorrect or invalid values are used in the parameters, the identifier will return the number "0".
© mIRC Discussion Forums