Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Memo field string need to split

Posted on 2014-10-28
9
Medium Priority
?
268 Views
Last Modified: 2014-11-05
In Crystal Report XI R2 I have a memo filed that has text in.
I need to split this text in two fields.  For this I was thinking about creating two formulas.
 Usually in the middle of text there is Chr(13) and Chr(10).  It looks easy to solve this, just use InStr to find its position and then use left or right function to pull out first part of text then second part.
However or but.
Problem is that user entering text sometimes put two times Chr(13),Chr(10),Chr(13),Chr(10) in the middle of text.
Sometimes he is putting chr(160) in too and it looks …..Chr(13),Chr(10),Chr(160),Chr(13),Chr(10)…
Sometimes user start text with Chr(13),Chr(10) or Chr(160)  or he first enters  tab Chr(9) then start to enter text.
I need to remove all from left side(beginning of text e.g.Chr(13),Chr(10),Chr(9),Chr(160)).
I  need text starts with capitalizing first letter of text. I need to find first occurrence of Chr(13),Chr(10) then extract text before that .
Then  in need to remove eventually Chr(13),Chr(10) or Chr(160) or Chr(9) from beginning of second part of text  .For the second part of text I have to cut everything after end of text  as user could put Chr(13),Chr(10),Chr(9) or Chr(160) there too.That second part of text has to go to second formula.
0
Comment
Question by:Taras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 40408980
Try this idea

To get the first string
Create a formula - Testx
Global StringVar Array strArray;
strTest := Replace(strTest,chr(160),'');
strTest := Replace(strTest,chr(9),'');

strArray := Split(strTest,chr(13)+chr(10));
strArray[1]

Open in new window


To get other strings (second string)
EvaluateAfter({@Testx});
Global StringVar Array strArray;
If UBOUND(strArray) >= 2 AND Len(strArray[2]) >= 1 then
    strArray[2]

Open in new window

Third String (if there are multiple chr(13) + chr(10))
EvaluateAfter({@Testx});
Global StringVar Array strArray;
If UBOUND(strArray) >= 3 AND Len(strArray[3]) >= 1 then
    strArray[3]

Open in new window


Just add as many as necessary

mlmcc
0
 
LVL 35

Assisted Solution

by:James0628
James0628 earned 1000 total points
ID: 40409028
The first text section always ends with Chr(13)-Chr(10) ?  You can't have just one of those, or Chr(10) first, or a Tab before them, etc.?

 Assuming that it always ends with Chr(13)-Chr(10), possibly followed by other things, here's another approach.

 This formula extracts the first section, and removes any Chr(10), etc. characters that might be at the very beginning:

Local StringVar tmp;

tmp := {your field};

while Left (tmp, 1) in [ ChrW (13), ChrW (10), ChrW (9), ChrW (160) ] do
  tmp := Mid (tmp, 2);

if tmp <> "" then
  Split (tmp, ChrW (13)) [ 1 ]


 This formula extracts the second section (if there is one), and removes any Chr(13), etc. characters that might be at the very beginning of that:

Local StringVar tmp;

tmp := {your field};

while Left (tmp, 1) in [ ChrW (13), ChrW (10), ChrW (9), ChrW (160) ] do
  tmp := Mid (tmp, 2);

if not (ChrW (13) in tmp) then
  ""
else
(
  tmp := Mid (tmp, InStr (tmp, ChrW (13)));
  while Left (tmp, 1) in [ ChrW (13), ChrW (10), ChrW (9), ChrW (160) ] do
    tmp := Mid (tmp, 2);
  tmp
)


 If you could have Chr(13), etc. characters at the end of the second section, that formula does not remove those.  It could.  I just didn't know if they were an issue.

 James
0
 

Author Comment

by:Taras
ID: 40409043
mlmcc

I got this error In formula testx

Global StringVar Array strArray;
StringVar strTest;

strTest := Replace(strTest,chr(160),'');
strTest := Replace(strTest,chr(9),'');

strArray := Split(strTest,chr(13)+chr(10));
strArray[1];----- A subscript must be between 1 and the size of the array.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:James0628
ID: 40409121
You'll get that error if the field is empty.  Try replacing the last line with this:

if chr(13)+chr(10) in strTest then
  strArray[1]


 James
0
 

Author Comment

by:Taras
ID: 40409142
I made mistake I did not replace strTest with my table field.
It removed error : A subscript must be.....
Do I still need to put this suggestion as James said?
0
 
LVL 35

Expert Comment

by:James0628
ID: 40409156
You would only need a check like that if the field could be completely empty (not even a space).  If the field will never be empty, you shouldn't need that test, but I don't think there would be any harm in including it anyway, just to play it safe.

 James
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 1000 total points
ID: 40409193
I would add a line at the top to test for a NULL string.  If the chr(13)chr(10) aren't there the array will still have an element

Global StringVar Array strArray;
 StringVar strTest;

If IsNull({YourField}) then
    ""
Else
(
 strTest := Replace({YourField},chr(160),'');
 strTest := Replace(strTest,chr(9),'');

 strArray := Split(strTest,chr(13)+chr(10));
 strArray[1];
)

Open in new window


mlmcc
0
 
LVL 35

Expert Comment

by:James0628
ID: 40409447
You'll also get an error if the string is empty (not null).  For example, the following will give you an error:

Split ("", ",") [ 1 ]

 James
0
 

Author Closing Comment

by:Taras
ID: 40424159
Thanks a lot
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question