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
Related
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.
I have a formula field in my crystal report which is set as "Html Text" in text interpretation. I want to add Line Break So I simply use this
"<br>"&{MyField}
But I want to add Line break dynamically such as it should be aligned according to my field value. For example, if field value is 2 then there will be 2 line breaks or if value is 5 then line breaks will be 5 like this.....
if {LineBreak} = 5 then
"<br><br><br><br><br>"&{MyField}
if {LineBreak} =2 then
"<br><br>"&{MyField}
How can I achieve this?
Use a loop to add <br>s; something like:
Local NumberVar i;
Local StringVar lineBreaks;
lineBreaks := "";
for i := 1 to {LineBreak} do (
lineBreaks := "<br>" & lineBreaks;
);
lineBreaks & {MyField};
instead of HTML you can directly use Chrw(13) in normal formula field.
try below code:
Local Numbervar i;
Local Numbervar j;
Local Stringvar break;
Local Stringvar break1;
for i:=1 to count(databasefield) do
(
break1:="";
for j:=1 to i do
(
if databasefield=i
then break:=break+chrw(13)
);
break1:=break1+break+databasefield;
);
break1;
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")
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]', '')
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.