Mask address in Crystal Reports - crystal-reports

I am creating a report by Crystal Reports which will mask address field depending upon parameter set to the report. I know this can be done using formula. I can successfully mask with hard coded value. However I need something like password masking. For example, if address is D/302 ABC apartment, it should be displayed as X/XXX XXX XXXXXXXXX. Only characters and numbers to be masked space and special characters not be masked. In addition length of masked data should match actual data.

I think you can use a formula like this:
Local StringVar str := "";
Local NumberVar strLen := Length({User.Address});
Local NumberVar i;
For i := 1 To strLen Do
(
if (ChrW({User.Address}[i]) in (AscW("A") to AscW("Z"))) or (ChrW({User.Address}[i]) in (AscW("a") to AscW("z"))) or (ChrW({User.Address}[i]) in (AscW("0") to AscW("9"))) Then
str := str + "X"
else
str := str + {User.Address}[i];
);
str

Logic is correct.. I have done the same thing by using Mid function instead of chrW (). No need to use asw () either. Simply use range operator.

Logic is correct.. I have done the same thing by using Mid function instead of chrW (). Additional you can use formula as ReplicateString ("X",len(address));
Only problem is space will be also masked

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;

mask a field with no fixed length in crystal reports 2008

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.

Format number formula

I have a number field in Crystal Report that must be shown in a specific format:
Eg:
12345678
must be shown as
1234-5678
I'm using a formula to transform the number to string, substring it 2 times and concatenate both values:
StringVar ordenT := Totext(GroupName ({DataTableInfCR.Orden}));
StringVar OrdenT1 := MID(ordenT,1,4);
StringVar OrdenT2 := MID(ordenT,4,4);
StringVar NroOrden := OrdenT1 +"-"+ OrdenT2;
However, the output for this code ends up being somthing like this:
12.3-45.6
I'm sure it because the default number format is with dots (ex: 12345678 will be 12.345.678)
How can I change the format via formula before my code??
Thanks!
To answer your question, to remove the decimals you use
StringVar ordenT := Totext(GroupName ({DataTableInfCR.Orden}),0);
or
StringVar ordenT := cStr(GroupName ({DataTableInfCR.Orden}),0);
EDIT:
See if this will take care of it all:
totext(GroupName({DataTableInfCR.Orden}),0,""),"xxxx-xxxx")

how to add leading zero to a text field in crystal reports

I'm trying to think of a way to add a leading zero to a string field value.
For example I have 12345 but need a formula that would convert it to 012345. I'm new to Crystal as I know that this is probably a simple formula but cant seem to get it to work.
12345 => 012345 (add leading zero to make it 6 chars)
Thanks in advance.
Try this
totext(your_number, "000000");
1st arg.: Well, it's the input.
2nd arg.: Number of digits you need in the output.
For ex,
num = 1234;
totext(num, "000000");
Output:
001234
And, if you want to add a fixed number of zeroes, then you can just use (to add 3 leading zeroes):
"000" + totext(your_number, 0); // to add 3 leading zeroes
Note: The final output is a string not a number.
To pad a numeric string value with zeroes to a certain length:
local numbervar yournum := tonumber({table.your_string}); //convert to number
totext(yournumnum, '000000') //convert back to padded string of length 6
OR for a universal string
local stringvar yourstring:= {table.your_string};
local numbervar LENGTH := 10; //The desired padded string length
if length(yourstring) >= LENGTH then yourstring else
replicatestring('0',LENGTH-length(yourstring)) + yourstring
how to use the formula in your crystal report,
to put below mention formula in ( open (field explorer)-->then right click(Formula field)-->select new--->create formula name(xyz)-->then put
** ToText({DataTable1.Sr_No},"0000") **
copy/past only bold text between ** and then save and close
after that formula you add to your crystal report and run, your required answer is there,
Sr_No.
0001
0002
0003
just put on your field '0'+yourstringchar
Above the logic works and its a generic formula to left padding
if you want right padding use this
local stringvar yourstring:= {table.your_string};
local numbervar LENGTH := 10; //The desired padded string length
if length(yourstring) >= LENGTH
then yourstring
else
yourstring + replicatestring('0',LENGTH-length(yourstring))
--kanthi
Right("00000000"&ToText({Table.correla}),8)
I use this:
replace((space((20)-len({Table.Field}))+({Table.Field}))," ","0")
Basically it makes leading spaces, but then replaces those spaces with zeros. By subtracting the length of the field from the added spaces, the field will always be the number of characters specified in space((XX)...
It looks overly-complex, but it actually simplifies reports that require numerous fixed-length fields. As I develop the report, I can copy-paste this code to a new formula, change the number of spaces to match the required field length, then change my field name.

Formatting specific found words within a text string in Crystal Reports

I have a list of words that I am searching through a "Notes" field within a table, that when I display that Notes field in my Crystal Report, I would like to somehow highlight (change font color) for only the specific flagged word within the note text string.
Example:
word list: Joe, Sarah, Amy, Jeff
note text: "I stopped by and talked with Joe to check on the account status, and Amy said hello."
desired result: Note text displays in the report with the words "Joe" and "Amy" in red.
I've tried using RTF and HTML in the Text Interpretation parameter within the properties, where I can successfully format the note text to either of these text outputs. However, I still don't know the right code to isolate and format the specific words from my list, especially if more than one of my words shows up within the field text.
Thanks in advance for any help you can give me!
I know this is old, but i found it searching for an issue i had. The answered code works, but seemed a bit cluttered for me, and also i needed to be able to provide a list of words to highlight. Here is what i came up with.
Local Stringvar Array searchwords:=MakeArray("Joe", "Sarah", "Amy");
local stringvar notes:={Notes};
local numbervar i;
for i:=1 to count(searchwords) do (
notes:=replace(notes,searchwords[i],"<font color='red'>" & searchwords[i] & "</font>",1,-1,1);
);
notes
The only thing to note, is that this will find results when the search word is part of a larger word - i.e. "WORK" would be BOLDED in "Workshop".
While this works for our needs as we want "working","work","worked" etc. to all highlight, crystal reports not supporting Regex is quite a large downside.
I did something similar a couple of years ago:
StringVar SearchText := "has";
StringVar Htm1 := "<b>";
StringVar Htm2 := "</b>";
StringVar Result := "";
StringVar Temp := "";
NumberVar Start := 1;
NumberVar Ln := Len(SearchText);
NumberVar Loc := Instr({#TextField}, SearchText);
While Loc > 0 Do (
Temp := Mid({#TextField}, Start, Loc - Start) + Htm1 + Mid({#TextField}, Loc, Ln) & Htm2;
Result := Result + Temp;
Start := Loc + Ln;
Loc := Instr(Start, {#TextField}, SearchText);
);
Temp := Mid({#TextField}, Start);
Result := Result + Temp;
Result
In this case I am searching the field called #TextField for the value in SearchText and am bolding the values. Probably not the most efficient code, but it works.