Author |
Message
|
wmqiadmin |
Posted: Tue Mar 06, 2007 7:48 am Post subject: SUBSTRING |
|
|
 Disciple
Joined: 19 Jun 2005 Posts: 163 Location: epping UK
|
I am trying to substring an incomming string....my code is
DECLARE msgLen INT;
DECLARE msgFinLen INT;
SET msgLen = LENGTH(myChar);
SET msgFinLen = msgLen-19;
SET myChar = SUBSTRING(myChar FROM 18 FOR msgFinLen);
the substring function doesn't trucate the last 19 characters its only trucating last 2 charactes....
Can any buddy explain me what I am doing wrong or is some thing wrong with the code.
thanks
wmqiadmin |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Mar 06, 2007 7:50 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Your substring is going to start reading at the 18th character.
It will then take however many characters are left, but not more than msgFinLen. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wmqiadmin |
Posted: Tue Mar 06, 2007 8:00 am Post subject: |
|
|
 Disciple
Joined: 19 Jun 2005 Posts: 163 Location: epping UK
|
jefflowrey wrote: |
Your substring is going to start reading at the 18th character.
It will then take however many characters are left, but not more than msgFinLen. |
That is true I want to remove first 18 char and last 18 char from the string.... but this code is removing the first 18 char that is working fine but not removing the last 19 char... its just truncating last 2 char...
any idea why?? |
|
Back to top |
|
 |
wmqiadmin |
Posted: Tue Mar 06, 2007 8:01 am Post subject: |
|
|
 Disciple
Joined: 19 Jun 2005 Posts: 163 Location: epping UK
|
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Mar 06, 2007 8:05 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
jefflowrey wrote: |
It will then take however many characters are left, but not more than msgFinLen. |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Mar 06, 2007 9:23 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
Quote: |
I am trying to substring an incomming string....my code is
DECLARE msgLen INT;
DECLARE msgFinLen INT;
SET msgLen = LENGTH(myChar);
SET msgFinLen = msgLen-19;
SET myChar = SUBSTRING(myChar FROM 18 FOR msgFinLen);
the substring function doesn't trucate the last 19 characters its only trucating last 2 charactes....
Can any buddy explain me what I am doing wrong or is some thing wrong with the code.
|
Let's say you have a 10 character string, but you only want characters 4,5,6, and 7.
The length of the string is 10.
You don't want the last 3.
So you set the length to go for to 10-3 = 7.
Then you start at character 4.
So from 4, for a length of 7.
And that equals ----> 4,5,6,7,8,9,10.
As you can see, you only wanted 4 characters, but ended up with 7. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Mar 06, 2007 10:03 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
special_agent_Queue wrote: |
As you can see, you only wanted 4 characters, but ended up with 7. |
I'd say "asked for" not "ended up with". _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Lisa |
Posted: Tue Mar 06, 2007 10:33 am Post subject: |
|
|
Master
Joined: 07 Jun 2002 Posts: 287 Location: NJ
|
special_agent_Queue wrote: |
Quote: |
I am trying to substring an incomming string....my code is
DECLARE msgLen INT;
DECLARE msgFinLen INT;
SET msgLen = LENGTH(myChar);
SET msgFinLen = msgLen-19;
SET myChar = SUBSTRING(myChar FROM 18 FOR msgFinLen);
the substring function doesn't trucate the last 19 characters its only trucating last 2 charactes....
Can any buddy explain me what I am doing wrong or is some thing wrong with the code.
|
Let's say you have a 10 character string, but you only want characters 4,5,6, and 7.
The length of the string is 10.
You don't want the last 3.
So you set the length to go for to 10-3 = 7.
Then you start at character 4.
So from 4, for a length of 7.
And that equals ----> 4,5,6,7,8,9,10.
As you can see, you only wanted 4 characters, but ended up with 7. |
It should read You don't want the first 3., not last 3. |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Tue Mar 06, 2007 11:32 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
jefflowrey wrote: |
special_agent_Queue wrote: |
As you can see, you only wanted 4 characters, but ended up with 7. |
I'd say "asked for" not "ended up with". |
Good point.
Lisa wrote: |
It should read You don't want the first 3., not last 3. |
It SHOULD be both, but I was going through the process that wmqiadmin went through, and attempting to lead him to that conclusion. |
|
Back to top |
|
 |
wmqiadmin |
Posted: Tue Mar 06, 2007 12:56 pm Post subject: |
|
|
 Disciple
Joined: 19 Jun 2005 Posts: 163 Location: epping UK
|
Thanks Guys,
special_agen_queue is correct.
After doing finalLeng = Orig-35 i was able to get the actual message what i was looking for. Where initially i was just removing the last characters not the initial ones.
Thanks once again guys for all your support.
wmqiadmin |
|
Back to top |
|
 |
|