egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Remove a concrete blank character

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Tue Jun 13, 2017 11:49 am    Post subject: Remove a concrete blank character Reply with quote

I have a variable that stores the artist name and the song separated by a hyphen.
The variable can return this format: Artist-Song
or
this format: Artist - Song

I have made this script that works only for one of the options.

Example:
Code:
bind pub n|n !t testing
   
proc testing {nick uhost handle chan text} {   
set liveme "Janis Joplin-Piece Of My Heart"   
 putquick "PRIVMSG $chan :\<artistName\>[lindex [split $liveme "-"] 0]\<\/artistName\>"
 putquick "PRIVMSG $chan :\<songName\>[lindex [split $liveme "-"] 1]\<\/songName\>"
  }


Returns what I want:
Quote:
17:34 @mybot <artistName>Janis Joplin</artistName>
17:34 @mybot <songName>Piece Of My Heart</songName>


But...
If the variable contains the other format, spaces are left after the artist name and before the song name.

Example2:
Code:
bind pub n|n !t testing
   
proc testing {nick uhost handle chan text} {   
set liveme "Janis Joplin - Piece Of My Heart"   
 putquick "PRIVMSG $chan :\<artistName\>[lindex [split $liveme "-"] 0]\<\/artistName\>"
 putquick "PRIVMSG $chan :\<songName\>[lindex [split $liveme "-"] 1]\<\/songName\>"
  }


Return this I do NOT want:
Quote:
17:34 @mybot <artistName>Janis Joplin </artistName>
17:34 @mybot <songName> Piece Of My Heart</songName>


I need the format to always be the same regardless of the value of the variable.
I need always to achieve this:
Quote:
<artistName>Janis Joplin</artistName>
<songName>Piece Of My Heart</songName>


EDIT: Fixed!
Code:
bind pub n|n !t testing
   
proc testing {nick uhost handle chan text} {   
set liveme ""Janis Joplin - Piece Of My Heart""   
set liveme1 "\<artistName\>[lindex [split $liveme "-"] 0]\<\/artistName\>"
set liveme2 "\<songName\>[lindex [split $liveme "-"] 1]\<\/songName\>"

set liveme1 [string map [list " </" "</"] $liveme1]
set liveme2 [string map [list "> " ">"] $liveme2]
    
  putmsg $chan "$liveme1"
  putmsg $chan "$liveme2"
  }

If you know of any more abbreviated or better, please share it. Smile
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
silentziler
Voice


Joined: 09 Sep 2015
Posts: 10

PostPosted: Wed Jun 21, 2017 6:37 pm    Post subject: Re: Remove a concrete blank character Reply with quote

Alternative:

regsub -all { <} $liveme1 {<} liveme1
regsub -all {> } $liveme2 {>} liveme2

instead of using [string map]
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Thu Jun 22, 2017 12:41 am    Post subject: Reply with quote

First format:
Code:

% set liveme "Janis Joplin - Piece Of My Heart"
Janis Joplin - Piece Of My Heart
% set pos [lsearch $liveme "-"]
2
% lrange $liveme 0 [expr $pos - 1]
Janis Joplin
% lrange $liveme [expr $pos + 1] end
Piece Of My Heart

Second format:
Code:

% set liveme "Janis Joplin-Piece Of My Heart"
Janis Joplin-Piece Of My Heart
% lsearch $liveme "-"
-1
% set liveme [join [split $liveme "-"] " - "]
Janis Joplin - Piece Of My Heart
% set pos [lsearch $liveme "-"]
2
% set liveme1 [lrange $liveme 0 [expr $pos - 1]]
Janis Joplin
% set liveme2 [lrange $liveme [expr $pos + 1] end]
Piece Of My Heart

And a code that accept both formats and gives the same result:
Code:

set liveme "Janis Joplin-Piece Of My Heart"

set pos [lsearch $liveme "-"]
if {$pos == -1} {
   set liveme [join [split $liveme "-"] " - "]
   set pos [lsearch $liveme "-"]
}

set liveme1 [lrange $liveme 0 [expr $pos - 1]]
set liveme2 [lrange $liveme [expr $pos + 1] end]

Works regardless of the format, meaning with or without space.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Thu Jun 22, 2017 9:46 am    Post subject: Reply with quote

That's why I like programming so much, and especially eggdrop.

The same results can be obtained in several ways.

Thanks to silentziler and caesar for sharing alternatives. Very Happy
_________________
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber