Well, that's no ordinary rabbit!

String maipulation, extraction, and other mangling

Note: In counting characters remember that the first position is 0 not 1.

Unless otherwise noted assume the variable STR contains the string "THIS IS MAGIC".

Using % (to the right)

%x Returns characters to the right of the x-th character

STR%2 would return "S IS MAGIC"

'%x Returns characters not to the right of the x-th character

STR'%2 would return "THI"

Using $ (to the left)

$x Returns characters to the left of the x-th character

STR$2 would return "TH"

'$x Returns characters not to the left of the x-th character

STR'$2 would return "IS IS MAGIC"

Using # (exact location)

#x Returns the x-th character

STR#8 would return "M"

'#x Returns all characters except for the x-th character

STR'#8 would return "THIS IS AGIC"

This is useful for things like removing the hyphens from a SS#. For this example assume STR contains 123-45-6789

STR'#6'#3 would return 123456789

#"xc" Returns the characters to the left of the x-th occurrence and to the right of the (x-1) occurrence (again start counting with 0) of the character c. Think of this as breaking the string into pieces, the breaking point being the character c. Only punctuation characters may be used.

STR#"0 " would return piece 0 - "THIS"
STR#"1 " would return piece 1 - "IS"
STR#"2 " would return piece 2 - "MAGIC"

One of the most common uses is to break a name field into last and first names. For these examples assume that STR contains "JONES,SARAH J".

STR#"0," would return the last name - "JONES"
STR#"1," would return the first name and middle name/initial - "SARAH J"
STR#"1,"#"0 " would return just the first name - "SARAH"
STR#"1,"#"1 " would return the middle name/initial - "J"

'#"xc" Returns the characters excluding those in the x-th c piece

STR'#"0 " would return all but piece 0 - " IS MAGIC"
STR'#"1 " would return all but piece 1 - "THIS MAGIC"
STR'#"2 " would return all but piece 2 - "THIS IS "

Using L (length or locate)

L returns the length of a string or the location in a string where a specific substring is found. It can be used to determine how long a string is or if it contains another string. L(STR) simply returns the length of the string. L(STR,STR2) returns the location in STR where STR2 starts or the length of STR if it does not contain STR2.

In these examples:
STR2 = "OF"
STR3 = "TOM"

L(STR) would return 24 (if I counted right)
L(STR,STR2) would return 18
L(STR,STR3) would return 24
L(STR,"S") would return 4

One example of it's use would be to check if the patient name has the letter X in it. Why you would want to do that I don't know.


Other Magic Pages

CDS Attributes Emailing Messages Emailing Scheduled Reports
@W. prompts String Manipulation NPR Viewer
Text Edit/View Attribute Meds in an NUR CDS NUI Desktop Icons
Field Attributes Lab results in a CDS Ultimate Message Box
Display Message Attributes Run NPR Report Attribute Multiple Query Checklist
NUR Canned Text in Query Mousetributes LAB TEST VIEW GROUP
OA Msg from PHA Rule FTP Standard Report HTML Pt Master Logs
PCI NPR Report

Don't see what you need?  Visit one of these other sites

Iatric Systems web site
NPR tips
NPR reports
Magic and C/S Products
Hosted by Daniel Davis
Resources for the IT Nurse
Articles and Discussion Forum
Debbie Kelly web site
Meditech tips
Nursing Informatics
Debbie Bate-Travis web site
Links to other attribute sites
Links to Nursing Informatics sites
Magic NPR Report Writing
Blogged by John Sharpe
NPR Report Writing Tips

or email me your request (tomt at thomast357.com).