Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: how to separate string? Post Reply Post New Topic
Author Message
nebchill26
Newbie
Newbie


Joined: 06 Nov 2008
Location: Philippines
Online Status: Offline
Posts: 20
Quote nebchill26 Replybullet Topic: how to separate string?
     Posted: 26 Jun 2011 at 3:21pm
hi does anyone know how to separate the 0 in this string? "000000000006628", i just need to separate the "0" from 6628 or any other number and sometimes the string can be like this "00002986".The separated string must look like this "00000000000" and "6628". Your help will be much appreciated. Thanks


Edited by nebchill26 - 26 Jun 2011 at 3:38pm
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 27 Jun 2011 at 3:06am
Okay, so like with many of my posts, there may be a simpler solution, but mine will work as well. Create two formulas.

Formula 1:
To get the Non-Zero number:
local stringvar nReverse:=strreverse({@OriginalString});
nReverse:=left(nReverse, instr(nReverse, '0')-1);
strreverse(nReverse)
;

Formula 2:
To get the Zeroes:
evaluateafter({@NonZeroString});
local numbervar nStringLength:=len({@OriginalString});
local numbervar nLengthNonZero:=len({@NonZeroString});

left({@OriginalString}, instr({@OriginalString}, '0')+(nStringLength - nLengthNonZero-1));






Edited by FrnhtGLI - 27 Jun 2011 at 3:09am
|< /\ '][' ( )
IP IP Logged
nebchill26
Newbie
Newbie


Joined: 06 Nov 2008
Location: Philippines
Online Status: Offline
Posts: 20
Quote nebchill26 Replybullet Posted: 27 Jun 2011 at 3:00pm
hey its great! thanks for the reply man! just a follow up question what about if the string is "0000062800" can i still split this as "00000" and "62800" using the same formula?
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 27 Jun 2011 at 4:37pm
Looking at his formula it appears you can.He's pulling off the "0's" from the left of the number string up to the positive numbers and leaving everything else.I freely admit I'm not the best when it comes to formulas though so you may have to give it a real world test to make sure.
IP IP Logged
nebchill26
Newbie
Newbie


Joined: 06 Nov 2008
Location: Philippines
Online Status: Offline
Posts: 20
Quote nebchill26 Replybullet Posted: 27 Jun 2011 at 5:09pm
i tried it using it but when i put a zero(0) on the right most part the formula wont split the string
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 28 Jun 2011 at 1:58am
Sorry, but as you have found out, my formula will not work if zeros are at the end of the number.

I believe I have found a more simple solution that will work even if zeros are at the end.

Formula 1:
Non-Zero number (with or without zeros at the end):

replace(totext(cdbl({@OriginalString}),0), "," , "")

You should be able to keep the second formula as it is.

Hope this one works for you.


Edited by FrnhtGLI - 28 Jun 2011 at 1:58am
|< /\ '][' ( )
IP IP Logged
nebchill26
Newbie
Newbie


Joined: 06 Nov 2008
Location: Philippines
Online Status: Offline
Posts: 20
Quote nebchill26 Replybullet Posted: 28 Jun 2011 at 10:25pm
It works!Thank you very much for your help!  Thumbs%20Up
IP IP Logged
Printable version Printable version

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