Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Field Output Post Reply Post New Topic
Author Message
mpaddock
Newbie
Newbie


Joined: 21 Jan 2009
Location: United States
Online Status: Offline
Posts: 6
Quote mpaddock Replybullet Topic: Field Output
     Posted: 28 Jan 2009 at 1:05pm
We have a string field that is this similar to this: 3.02.04.00.00.00.00 . Is there a way to strip out the padded "0" after a period?

Edited by mpaddock - 28 Jan 2009 at 1:34pm
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 29 Jan 2009 at 6:34am
haven't done loops lately, but for just one (looping is easy after that) I would try:
local numbervar zero;
local stringvar orig={field};
 
zero := instr(orig, ".0");
if zero then
  orig = left(orig, zero) + mid(orig, zero + 2);
 
Hope this helps
IP IP Logged
mpaddock
Newbie
Newbie


Joined: 21 Jan 2009
Location: United States
Online Status: Offline
Posts: 6
Quote mpaddock Replybullet Posted: 29 Jan 2009 at 9:10am
ok, this didn't work. After I posted this, I realized I was not completely clear on what I needed. I need this String 3.03.03.00.00.00.00 converted to this 3.3.3. Here is the code I created in a new formula from what was suggested:
local numbervar zero;
local stringvar orig={Observations.Standard};
zero := instr(orig, ".0");
if zero then
  orig = left(orig, zero) + mid(orig, zero + 2);

If I do a check on this code, I get A boolean is required here and the zero is highlighted in the if zero then statement.  I changed the numbervar to a stringvar and I get A string is required here and instr(orig, ".0") is highlighted.
Anyone else like to take a whack at it?


Edited by mpaddock - 29 Jan 2009 at 9:12am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Jan 2009 at 9:43am
if your string is always in the format of:
x.0x.0x.00.00.00.00
You can use:
left({field},2) + mid({field},4,2) + mid({field},7,1)
 


Edited by DBlank - 29 Jan 2009 at 9:45am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 29 Jan 2009 at 10:15am
OOPS! thought it would work, but you would want to change it to zero > 0 that solves the boolean issue.  That would only remove 1 instance...  you still need to look up in help to loop, it didn't appear to be too hard.
 
With the additional requirement, you would need to loop through again and get rid of '..'.
 
So if you KNOW that you don't need anything after the 2nd dot(.) I would truncate the string and then use the formula...UNLESS you know that values will ALWAYS be 1 digit, then DBlank way is way simpler.
IP IP Logged
mpaddock
Newbie
Newbie


Joined: 21 Jan 2009
Location: United States
Online Status: Offline
Posts: 6
Quote mpaddock Replybullet Posted: 29 Jan 2009 at 11:55am
Ok, I found an easier way by using this:
Replace({Observations.Standard},".0",".")
 
thanks for everyone's help.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Jan 2009 at 6:03am
Great!  I didn't know that there was a replace function...way easier my original method.
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