Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

kerrplunk (TechnicalUser) (OP)
11 Aug 09 10:52
In CR10, is it possible to extract particular parts from a string?

I am trying to build a report that shows CIs that have changed location on our CMDB using the history line that is created when the field is updated which reads like:

Room No. from "4" to "6".
or
Room No. from "56" to "Store".

I was hoping to extract, into two seperate fields the bits between the double-quotes (ie the 4 and 6). To complicat ematters for me, the quoted data can be anything (text or numeric)up to 40 characters in length.

Any ideas? I've looked at various things like Split, but I get confused (easily!) by trying to include the quotes.

Thanks.
 
Helpful Member!(3)  CoSpringsGuy (IS/IT--Management)
11 Aug 09 11:13
ok its really ugly but it will work

formula for piece one
numbervar a := instr({@yourfield},'"');
numbervar b := instr({@yourfield},'to');
stringvar pieceone := trim(replace(mid({@yourfield},a,(len({@yourfield})-b)-2),'"',""));
pieceone

formula for piece two
numbervar a := len({@yourfield});
numbervar b := instr({@yourfield},'to');
stringvar pieceone := trim(replace(replace(mid({@yourfield},b+2,a-b),'"',""),".",""));
pieceone

 

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

kerrplunk (TechnicalUser) (OP)
11 Aug 09 11:26
Thanks for your help.

Piece two works great, but for piece one I get an error: "Start position is less than 1 or not an integer"
CoSpringsGuy (IS/IT--Management)
11 Aug 09 11:56
is there always a value in that field? The only way I get that error is if I use a blank field or if the field does not have a " at all try adding the if statement to both formulas. It should read like this

numbervar a := instr({@yourfield},'"');
numbervar b := instr({@yourfield},'to');

if instr({@yourfield},'"') = 0 then "" else

stringvar pieceone := trim(replace(mid({@yourfield},a,(len({@yourfield})-b)-2),'"',""));
pieceone

 

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

kerrplunk (TechnicalUser) (OP)
11 Aug 09 12:05
OK, I got the first piece working by chucking some brackets around it.

But it is now producing inconsistent results as it  variously extracts the full remaining line of text (looks like if the quoted data isn't only a number) or stops when it gets to a space, or stops partway through a word (such as the inbetween 'to' which is after the second quote)

 
CoSpringsGuy (IS/IT--Management)
11 Aug 09 12:07
throw me out some more extreme examples of what your raw data looks like

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

CoSpringsGuy (IS/IT--Management)
11 Aug 09 12:24
I took another approach at your issue from the angle you were actually going with before I made it harder than it is. I initially looked at it and didnt think split would work because its a little different than data you would normally use split with. Buut I gave it a shot on the original example you gave and it works pretty well. I think where you may have been having problems was enclose the desired " for the split in ". you have to use single quotes.

Room No. from "4" to "6".

split({@yourfield},'"')[2]

results in 4


split({@yourfield},'"')[4]

results in 6

let me know if that works

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

kerrplunk (TechnicalUser) (OP)
12 Aug 09 4:35
That is great - it works brilliantly!

Now how does it work?!? (I think) I get the Splitting the field at the ", but where does the [2] and [4] come in to it (something to do with arrays)?
How does it know where to stop?

Thanks again.
CoSpringsGuy (IS/IT--Management)
12 Aug 09 10:51
the brackets indicate the index of the array. In the formula we used " as the character that separates the different values we wanted to assign the indexes to. So in your example when you use the split function it breaks the string down into an array with 5 indexes. The formula we created tells it to use [2] or [4].

Room No. from [1]
56 [2]
to [3]
Store [4]
. [5]

In my experience it is a little unusual to use the split in your scenario but it worked really well! I learned something from this one because I wasn't aware split would apparently assume the " at the beginning and end of the string.

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

chelseatech (Instructor)
12 Aug 09 18:15
Very smart.  Is it okay if I publish this in the next Crystal Clear newsletter?

Editor and Publisher of Crystal Clear
www.chelseatech.co.nz/pubs.htm

CoSpringsGuy (IS/IT--Management)
12 Aug 09 18:33
If you think someone might find it helpful then sure!

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close