For Programmers: Free Programming Magazines  


Home > Archive > Tcl > August 2006 > SPLIT problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SPLIT problem
Tom Conner

2006-08-25, 9:59 pm

I am trying to extract the boundry key from the headers in a HTML encoded
email. The key is in this string:

boundary="----=_NextPart_000_2B34_01C6C872.AAF863F0"

The part in the quotes is the key.

Doing this:
set part0 [lindex [split $linePart "y="] 0]
set part1 [lindex [split $linePart "y="] 1]
Log "PART0:\t$part0"
Log "PART1:\t$part1"

Results in this output:
PART0: boundar
PART1:

Why isn't PART1 equal to "----=_NextPart_000_2B34_01C6C872.AAF863F0"

Instead the string is split into these componets:
boundar {} {"----} _NextPart_000_2B34_01C6C872.AAF863F0\"

I do not want it split on the "=" sign, but only on the "y=".


Ingo Leschnewsky

2006-08-25, 9:59 pm

Hi Tom!

Tom Conner schrieb am 26.08.06 03:41:

> I am trying to extract the boundry key from the headers in a HTML encoded
> email. The key is in this string:
>
> boundary="----=_NextPart_000_2B34_01C6C872.AAF863F0"
>
> The part in the quotes is the key.
>
> Doing this:
> set part0 [lindex [split $linePart "y="] 0]
> set part1 [lindex [split $linePart "y="] 1]
> Log "PART0:\t$part0"
> Log "PART1:\t$part1"
>
> Results in this output:
> PART0: boundar
> PART1:
>
> Why isn't PART1 equal to "----=_NextPart_000_2B34_01C6C872.AAF863F0"
>
> Instead the string is split into these componets:
> boundar {} {"----} _NextPart_000_2B34_01C6C872.AAF863F0\"
>
> I do not want it split on the "=" sign, but only on the "y=".


You may [join] lists together with strings between them. But you can
[split] a string only at single characters.

Regards
Ingo
Alan Anderson

2006-08-25, 9:59 pm

"Tom Conner" <tconner@olopha.net> wrote:

> I am trying to extract the boundry key from the headers in a HTML encoded
> email. The key is in this string:
>
> boundary="----=_NextPart_000_2B34_01C6C872.AAF863F0"
>
> The part in the quotes is the key.
>
> Doing this:
> set part0 [lindex [split $linePart "y="] 0]
> set part1 [lindex [split $linePart "y="] 1]
> Log "PART0:\t$part0"
> Log "PART1:\t$part1"
>
> Results in this output:
> PART0: boundar
> PART1:
>
> Why isn't PART1 equal to "----=_NextPart_000_2B34_01C6C872.AAF863F0"


Take a closer look at how the [split] command works. It takes *each*
character you provide as a valid character to split at. That means that
"y" and "=" are *both* used as separators, yielding exactly what you say
you get.

> Instead the string is split into these componets:
> boundar {} {"----} _NextPart_000_2B34_01C6C872.AAF863F0\"
>
> I do not want it split on the "=" sign, but only on the "y=".


Sorry, [split] won't do what you want. [regexp] can, though I don't see
why you need to get any fancier than this:

set key [string range $linePart 9 end]

Actually, I believe

set key [string range $linePart 10 end-1]

would be more appropriate.
Tom Conner

2006-08-25, 9:59 pm


"Alan Anderson" <aranders@insightbb.com> wrote in message
news:aranders-9659BE.23064525082006@news.isp.giganews.com...
> "Tom Conner" <tconner@olopha.net> wrote:
>
encoded[color=darkred]
>
> Take a closer look at how the [split] command works. It takes *each*
> character you provide as a valid character to split at. That means that
> "y" and "=" are *both* used as separators, yielding exactly what you say
> you get.
>
>
> Sorry, [split] won't do what you want. [regexp] can, though I don't see
> why you need to get any fancier than this:
>
> set key [string range $linePart 9 end]
>
> Actually, I believe
>
> set key [string range $linePart 10 end-1]
>
> would be more appropriate.


I used regexp but will change to your second suggestion since I absolutely
HATE regexp code. My brain has been slow all day.

Its to bad that SPLIT cannot split on a defined char string instead of
treating each char in the string as a separate split delimiter.



Gerald W. Lester

2006-08-26, 4:00 am

Tom,

Split takes a set of characters to split on, not a string.

However the ::textutil::splitx procedure of the textutil package of TclLib
does split on any string.

That being said, you may want to look at the mime package of TclLib. It
most likely will address the real problem you are attempting to solve
instead of the issue you asked about.

Tom Conner wrote:
> I am trying to extract the boundry key from the headers in a HTML encoded
> email. The key is in this string:
>
> boundary="----=_NextPart_000_2B34_01C6C872.AAF863F0"
>
> The part in the quotes is the key.
>
> Doing this:
> set part0 [lindex [split $linePart "y="] 0]
> set part1 [lindex [split $linePart "y="] 1]
> Log "PART0:\t$part0"
> Log "PART1:\t$part1"
>
> Results in this output:
> PART0: boundar
> PART1:
>
> Why isn't PART1 equal to "----=_NextPart_000_2B34_01C6C872.AAF863F0"
>
> Instead the string is split into these componets:
> boundar {} {"----} _NextPart_000_2B34_01C6C872.AAF863F0\"
>
> I do not want it split on the "=" sign, but only on the "y=".
>
>



--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
Frank Ranner

2006-08-26, 4:00 am

Tom Conner wrote:
> "Alan Anderson" <aranders@insightbb.com> wrote in message
> news:aranders-9659BE.23064525082006@news.isp.giganews.com...
> encoded
>
> I used regexp but will change to your second suggestion since I absolutely
> HATE regexp code. My brain has been slow all day.
>
> Its to bad that SPLIT cannot split on a defined char string instead of
> treating each char in the string as a separate split delimiter.
>
>
>

why not [split $linePart {"}]


regards,
Frank Ranner
suchenwi

2006-08-26, 4:00 am


Gerald W. Lester schrieb:

> Split takes a set of characters to split on, not a string.
>
> However the ::textutil::splitx procedure of the textutil package of TclLib
> does split on any string.


Also, in the absence of tcllib, the simple workaround is:
set parts [split [string map [list $splitstr \uFFFF] $input] \uFFFF]
As \uFFFF is not a valid Unicode, it cannot be expected to occur in the
string

Ralf Fassel

2006-08-26, 4:00 am

* "Tom Conner" <tconner@olopha.net>
| Its to bad that SPLIT cannot split on a defined char string instead
| of treating each char in the string as a separate split delimiter.

Maybe 'string first' is what you're looking for:

set line {boundary="----=_NextPart_000_2B34_01C6C872.AAF863F0"}
set idx [string first "y=" $line]
=> 7
incr idx 2
set boundary [string range $line $idx end]

HTH
R'
Ralf Fassel

2006-08-26, 4:00 am

* Alan Anderson <aranders@insightbb.com>
| though I don't see why you need to get any fancier than this:
|
| set key [string range $linePart 9 end]

The string sounds like a MIME separator and comes usually with
whitespace or a Content-Type-specifier in front of it.

Content-Type: multipart/alternative;
boundary="--------8C8900B9D5DF19B_D54_..."

Sure, you can 'string trim' and so on, but 'string first' will be a
better solution here (see my other message).

R'
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com