mIRC Home    About    Download    Register    News    Help

Print Thread
#43485 22/08/03 01:47 AM
Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
Hi - I have a variable headline that is pulled from a txt file dumped from a website. Here's an example headline:

After Hours: Retail shares rise on quarterly results - Carolyn Pritchard

What I want to do is get rid of of the name that follows the headline (Carolyn Pritchard in this example but it's different for each story). So bascially, everything after the -
I've tried various $left $right combinations etc but because the number of characters in the name is always different, it dosn't work.
If anyone could help on this I'd appreciate it! Thanks
confused


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
$gettok(After Hours: Retail shares rise on quarterly results - Carolyn Pritchard,-1,45)

Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
thanks - but the headline and the name are different each time...


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Yes, and it will work each time (assuming they always have the name after the last -), just replace the first parameter with the variable you have the headline in.

Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
great - thats working very well now - thank you very much!


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
oops one more thing - is there a way for recognise the - only if it has a space after it? the reason being it's cutting off some headlines that have a - in words, like this one:

Schering-Plough warns, cuts dividend - Jeffry Bartash

thanks again...


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
$gettok(Schering-Plough warns $+ $chr(44) cuts dividend - Jeffry Bartash,-1,45) returns Jeffry Bartash, what's wrong with that?

Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
sorry it was only returning Schering because of the - between Schering-Plough

my line of script is this so far:
msg #NewsRoom 0,7ยป $mid($gettok(%mw,1,45),17)

so would there be a way for it to still include the - if there's no spaces either side and just cut it off if there is a space on each side like before the name at the end?


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
It's meant to be -1 for the second parameter, not just 1. No idea what the $mid is for.

Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
the $mid is to get rid of a date & time that's before the headline


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
and -1 only seems to return the last 2 letters of the persons name at the end so I tried 1 and it was correct


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Well it works fine here..type this:
/set %test Schering-Plough warns, cuts dividend - Jeffry Bartash
//echo -a $gettok(%test,-1,45)

If you get "Jeffry Bartash" then it is a problem with something else.

Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
yes I'm getting Jeffry Bartash - will have a look to see where the problem is...


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Code:
/getName {
  var %str = $$1-, %tok = $findtok(%str, -, $findtok(%str, -, 0, 32), 32) + 1
  return $gettok(%str, $+(%tok,-), 32)
}


Examples:

Code:
/getName {
  var %str = $$1-, %tok = $findtok(%str, -, $findtok(%str, -, 0, 32), 32) + 1
  return $gettok(%str, $+(%tok,-), 32)
}

/ex {
  var %str = This is some topic - Some name
  [color:Red]/echo -a %str[/color]
  [color:blue]/echo -a $getName(%str)[/color]

  var %str = This is some topic - Some hyphened-name
  [color:Red]/echo -a %str[/color]
  [color:blue]/echo -a $getName(%str)[/color]

  var %str = This is some hyphened-topic - Some name
  [color:Red]/echo -a %str[/color]
  [color:blue]/echo -a $getName(%str)[/color]

  var %str = This is some hyphened-topic - Some hyphened-name
  [color:Red]/echo -a %str[/color]
  [color:blue]/echo -a $getName(%str)[/color]

  var %str = This is some - hyphened and spaced topic - Some name
  [color:Red]/echo -a %str[/color]
  [color:blue]/echo -a $getName(%str)[/color]
}


Returns:

This is some topic - Some name
Some name
This is some topic - Some hyphened-name
Some hyphened-name
This is some hyphened-topic - Some name
Some name
This is some hyphened-topic - Some hyphened-name
Some hyphened-name
This is some - hyphened and spaced topic - Some name
Some name

EDIT: Color Coded

Last edited by KingTomato; 22/08/03 04:12 AM.

-KingTomato
Joined: Jan 2003
Posts: 109
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Jan 2003
Posts: 109
thanks alot KT - will venture into giving that a try! wink


#Newsroom
Where News & Markets Connect
http://www.inewsroom.net

Link Copied to Clipboard