mask a field with no fixed length in crystal reports 2008 - crystal-reports

I have a field in crystal reports that displays customer's names. the requirement however is to just display the first 5 characters, which includes spacing as well. whatever comes after the 5th character will be converted into * and the spacing shall be displayed as a space still. as the name field varies, how do i accomplish this?
currently i only have this, which displays the first 5 characters and replaces only the 6th character with an *
Replace({Command.CUST_NAME},MID({Command.CUST_NAME},6),"*")

Unfortunately, it seems Crystal does not suport regex.
So, i would do a function. Try this:
stringvar input := {Command.CUST_NAME};
stringvar output := MID(input, 1, 5);
numbervar i;
for i:=5 to Length (input) step 1 do (
stringvar aChar := MID(input, i, 1);
if aChar <> " " then aChar := "*";
output := output + aChar;
);
output
Maybe you will have to handle if {Command.CUST_NAME} is smaller than 5 chars.

Related

How to split data every n-th character and make it into array in crystal report

i want to split data to make it into array. so given for example: 12345678
i want to get string array like this => ["234","678"]
is it possible in crystal report?
Yes, it is possible. But the requirements are not clear.
Data type of input (string or Number?)
Logic: discard 1st character? Then, groups of 3 skipping the 4th character?
Here is formula code that takes "12345678" and returns "^234^678":
local stringvar myString := "12345678";
local stringvar myDelimitedString := "";
local numbervar StringLength := Len(myString);
local numbervar i;
For i := 1 to StringLength step 4 do
myDelimitedString := myDelimitedString + "^" + MID(myString, i+ 1, 3);
myDelimitedString;

Crystal Report formula issue :How to split multi line text value in to the array and how to fetch it by forloop in

I have one field in a dataset which has a multi-line textbox value. I want to split that record, store it into an array, and when I fetch the value from the array by a for-loop, I want to prepend a "*" to each line. I have written a formula for that but it's working only for 2 values. After that it's not working and I'm not able to get how to retrieve the value like this.
I want the result to be:
* 123
* 234
* 786
But I'm getting the result:
*123
234
786
my formula is
Local StringVar y;
Local StringVar x;
Local NumberVar i;
y := ""+ chrw(10);
x := y;
Stringvar Array strings := Split({Touche.Concerns}, "\r\n");
Stringvar Array numbers;
For i :=1 To Ubound(strings) Do
(
y := y + chrw(10)+ "$" + strings[i];
);
y;
Instead of a long formula which breaks into arrays and manipulates each line, why not just replace the line breaks with a line break and the asterisk?
"* " & replace(trim({Touche.Concerns}), "\r\n", "\r\n* ");
The leading '*' is to place the char on the first line and the trim function is called to remove any trailing line breaks (so there won't be a line with just the asterisk).
As a side note, use & when concatenating strings and not the + char. Use the + can sometimes cause coercion to where numeric values would be added together. For example "12" + "34" would yield 46 instead of 1234. The & char ensures string concatenation is used.

How to display only alphanumeric characters in Crystal Reports?

I'm looking to strip out any characters that aren't A-Z a-z or 0-9.
I set some code in the display string to basically white-list characters. Went about this as follows:
stringvar input := {report.field};
stringvar output := '';
numbervar i;
input := Trim(input);
for i := 1 to Length(input) Step 1 do
// 0-9 is 48-57
// A-Z is 65-90
// a-z is 97-122
if (input[i] in [Chr(48),Chr(49),Chr(50),Chr(51),Chr(52),Chr(53),Chr(54),Chr(55),Chr(56),Chr(57),Chr(65),Chr(66),Chr(67),Chr(68),Chr(69),Chr(70),Chr(71),Chr(72),Chr(73),Chr(74),Chr(75),Chr(76),Chr(77),Chr(78),Chr(79),Chr(80),Chr(81),Chr(82),Chr(83),Chr(84),Chr(85),Chr(86),Chr(87),Chr(88),Chr(89),Chr(90),Chr(97),Chr(98),Chr(99),Chr(100),Chr(101),Chr(102),Chr(103),Chr(104),Chr(105),Chr(106),Chr(107),Chr(108),Chr(109),Chr(110),Chr(111),Chr(112),Chr(113),Chr(114),Chr(115),Chr(116),Chr(117),Chr(118),Chr(119),Chr(120),Chr(121),Chr(122)])
then output := output + input[i];
output
If anyone has a cleaner/shorter way of doing this please share!
Create a SQL Expression:
//{%MY_FIELD}
// Oracle syntax
REGEXP_REPLACE(TABLE.FIELD, '[^0-9]', '')

Number to String in a formula field

I am using a formula field to concatonate 2 decimal values separated by a dash. However, I want the result to trim all unneccesary trailing zeros and decimal points for both values.
For example, I want values 10 and 8.5 to be "10 - 8.5". Now it shows "10.00 - 8.50".
The formula I am using is CSTR({field1}) + " - " + CSTR({field2}).
I believe this is what you're looking for:
Convert Decimal Numbers to Text showing only the non-zero decimals
Especially this line might be helpful:
StringVar text := Totext ( {Your.NumberField} , 6 , "" ) ;
The first parameter is the decimal to be converted, the second parameter is the number of decimal places and the third parameter is the separator for thousands/millions etc.
CSTR({number_field}, 0, '')
The second placeholder is for decimals.
The last placeholder is for thousands separator.
i wrote a simple function for this:
Function (stringVar param)
(
Local stringVar oneChar := '0';
Local numberVar strLen := Length(param);
Local numberVar index := strLen;
oneChar = param[strLen];
while index > 0 and oneChar = '0' do
(
oneChar := param[index];
index := index - 1;
);
Left(param , index + 1);
)

Crystal reports 11: How to handle or trim special characters

In my crystal report, I noticed one of the fields being pulled from a table has special characters. More specifically carriage returns and tabs. Is there a way to strip this out, so it doesn't show up blank in my reports?
Thanks in advance.
This should do it:
stringvar output := {TABLE_NAME.FIELD_NAME};
output := Trim(output); //get rid of leading & trailing spaces
output := Replace(output,Chr(13),''); //get rid of line feed character
output := Replace(output,Chr(10),''); //get rid of carriage return character
//add any other special characters you want to strip out.
If you have a lot of characters to strip out, you can use this slightly fancier approach. Just add whatever characters you want to strip out to the in[]:
stringvar input := {DROPME.TEST_FIELD};
stringvar output := '';
numbervar i;
input := Trim(input);
for i := 1 to Length(input) Step 1 do
if not(input[i] in [Chr(13),Chr(10)]) then
output := output + input[i];
output