Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

finding the largest token in a string

2 posts in General Discussion Last posting was on 2003-07-22 12:17:04.0Z
Richard Posted on 2003-07-22 11:34:34.0Z
From: "Richard" <Richardr@ldsinc.com>
Subject: finding the largest token in a string
Date: Tue, 22 Jul 2003 06:34:34 -0500
Lines: 13
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#6OfvZEUDHA.349@forums-2-dub>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: lds253.ldsinc.com 66.6.104.253
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1424
Article PK: 3657

Hello,

I have a Token string for the sake of this example looks like this
12|Abc|12344|Defgh|21|De|6543|abcdefgh|33|aa
Is there an elegant way to determine and return the largest token size? In
this example it is the 8th token or "abcdefgh" a size of of 8. I don't
nessarily need to know the token especially if there are 2 token's with the
same size but I do need to know the largest and return that.

Thanks
Richard


Breck Carter [TeamSybase] Posted on 2003-07-22 12:17:04.0Z
From: "Breck Carter [TeamSybase]" <NOSPAM__bcarter@risingroad.com>
Subject: Re: finding the largest token in a string
Date: Tue, 22 Jul 2003 08:17:04 -0400
Organization: RisingRoad Professional Services
Reply-To: NOSPAM__bcarter@risingroad.com
Message-ID: <9oaqhvkav2jooihu7g05ls4kb169o315jj@4ax.com>
References: <#6OfvZEUDHA.349@forums-2-dub>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: bcarter.sentex.ca 64.7.134.118
Lines: 58
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1426
Article PK: 3659

CREATE FUNCTION f_longest_token_length (
@token_string LONG VARCHAR )
RETURNS BIGINT
BEGIN
DECLARE @longest_token_length BIGINT;
DECLARE @prev_delimiter_pos BIGINT;
DECLARE @delimiter_pos BIGINT;

SET @longest_token_length = 0;
SET @prev_delimiter_pos = 0;
SET @delimiter_pos = LOCATE ( @token_string, '|' );

WHILE @delimiter_pos > 0 LOOP
IF @delimiter_pos - @prev_delimiter_pos - 1
> @longest_token_length THEN
SET @longest_token_length
= @delimiter_pos - @prev_delimiter_pos - 1;
END IF;
SET @prev_delimiter_pos = @delimiter_pos;
SET @delimiter_pos = LOCATE (
@token_string, '|', @delimiter_pos + 1 );
END LOOP;
IF LENGTH ( @token_string ) - @prev_delimiter_pos
> @longest_token_length THEN
SET @longest_token_length
= LENGTH ( @token_string ) - @prev_delimiter_pos;
END IF;
RETURN @longest_token_length;
END;

SELECT f_longest_token_length (
'12|Abc|12344|Defgh|21|De|6543|abcdefgh|33|aa|ASDFASDFASDF' );

...returns 12.

Breck

On Tue, 22 Jul 2003 06:34:34 -0500, "Richard" <Richardr@ldsinc.com>

wrote:

>From: "Richard" <Richardr@ldsinc.com>
>Subject: finding the largest token in a string
>Date: Tue, 22 Jul 2003 06:34:34 -0500
>Lines: 13
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <#6OfvZEUDHA.349@forums-2-dub>
>Newsgroups: ianywhere.public.general
>NNTP-Posting-Host: lds253.ldsinc.com 66.6.104.253
>Path: forums-master.sybase.com!forums-2-dub.sybase.com
>Xref: forums-master.sybase.com ianywhere.public.general:1453
>
>Hello,
>
>I have a Token string for the sake of this example looks like this
>12|Abc|12344|Defgh|21|De|6543|abcdefgh|33|aa
>Is there an elegant way to determine and return the largest token size? In
>this example it is the 8th token or "abcdefgh" a size of of 8. I don't
>nessarily need to know the token especially if there are 2 token's with the
>same size but I do need to know the largest and return that.
>
>Thanks
>Richard

bcarter@risingroad.com
Mobile and Distributed Enterprise Database Applications
http://www.risingroad.com