Wednesday, March 21, 2012

Replace character with new line

I'm relatively new to scripting in Crystal Reports, and was hoping someone might be able to offer some advice with a problem I'm having.

I have a database field that contains a large text string of comments. In this string are tilde characters, ~, and those are supposed to represent when to insert a new line. I'm trying to take that field and format it so that any tildes are replaced with a new line break. Here is what I have currently:

stringVar ItemList := "";
stringVar CommaChar := "";
numberVar i := 0;

For i:= 1 to count({AR_DIM.ORDER_HEADER_NOTES})

Do
(
If {AR_DIM.ORDER_HEADER_NOTES}[i] = "~" then
ItemList := ({AR_DIM.ORDER_HEADER_NOTES}[i]) + "\r\n"
Else
ItemList := ({AR_DIM.ORDER_HEADER_NOTES}[i]);
i = i+1;
) ;

ItemList

The result I get is only a single character, the first character in the original string.

I'm sure it's a rookie mistake, but anyone have any thoughts on what I'm doing wrong?stringVar ItemList := "";
stringVar CommaChar := "";
numberVar i := 0;
numbervar strLen := Length({AR_DIM.ORDER_HEADER_NOTES});

For i:= 1 To strLen

Do
(
If {AR_DIM.ORDER_HEADER_NOTES}[i] = "~" then
ItemList := ItemList + ({AR_DIM.ORDER_HEADER_NOTES}[i]) + "\r\n"
Else
ItemList := ItemList + ({AR_DIM.ORDER_HEADER_NOTES}[i]);
) ;

ItemList

No comments:

Post a Comment