source: FOIAVistA/tag/r/KERNEL-XU-A4A7-USC-XG-XLF-XNOA-XPD-XQ-XVIR-ZI-ZOSF-ZOSV-ZT-ZU-%Z-XIP--XQAB--XUC--XUR--ZIN--ZTED/XLFSTR.m@ 1540

Last change on this file since 1540 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 3.2 KB
Line 
1XLFSTR ;ISC-SF/STAFF - String Functions ;12/19/06 09:45
2 ;;8.0;KERNEL;**112,120,400,437**;Jul 10, 1995;Build 2
3 ;
4UP(X) Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
5 ;
6LOW(X) Q $TR(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
7 ;
8STRIP(X,Y) Q $TR(X,$G(Y),"")
9 ;
10REPEAT(X,Y) ;
11 N % Q:'$D(X) "" I $L(X)*$G(Y)>245 Q ""
12 S %="",$P(%,X,$G(Y)+1)=""
13 Q %
14 ;
15SPLIT(%SRC,%DLM,%VLIST) ;split a string by delimiter vars in list
16 ;returns number of vars in list
17 ;usage - s %=$$split(src,dlm,"d1,d2,d3,..")
18 N I,V,DV
19 S DV=$$DVARS(%VLIST),%DLM=$G(%DLM,",")
20 F I=1:1:$L(%VLIST,DV) S V=$P(%VLIST,DV,I) S:V'="" @V=$P(%SRC,%DLM,I)
21 Q I
22 ;
23DVARS(LIST) ;return a delimiter for a list of variables
24 Q $S(%VLIST[$C(9):$C(9),%VLIST[";":";",1:",")
25 ;
26INVERT(X) ;
27 N %,%1 S %="" F %1=$L(X):-1:1 S %=%_$E(X,%1)
28 Q %
29 ;
30REPLACE(IN,SPEC) ;See $$REPLACE in MDC minutes.
31 Q:'$D(IN) "" Q:$D(SPEC)'>9 IN N %1,%2,%3,%4,%5,%6,%7,%8
32 S %1=$L(IN),%7=$J("",%1),%3="",%6=9999 F S %3=$O(SPEC(%3)) Q:%3="" S %6(%6)=%3,%6=%6-1
33 F %6=0:0 S %6=$O(%6(%6)) Q:%6'>0 S %3=%6(%6) D:$D(SPEC(%3))#2 RE1
34 S %8="" F %2=1:1:%1 D RE3
35 Q %8
36 ;
37RE1 S %4=$L(%3),%5=0 F S %5=$F(IN,%3,%5) Q:%5<1 D RE2
38 Q
39RE2 Q:$E(%7,%5-%4,%5-1)["X" S %8(%5-%4)=SPEC(%3)
40 F %2=%5-%4:1:%5-1 S %7=$E(%7,1,%2-1)_"X"_$E(%7,%2+1,%1)
41 Q
42RE3 I $E(%7,%2)=" " S %8=%8_$E(IN,%2) Q
43 S:$D(%8(%2)) %8=%8_%8(%2)
44 Q
45 ;
46RJ(%,%1,%2) ;Right justify
47 N %3
48 S:%1["T" %1=+%1,%=$E(%,1,%1)
49 S %3=$J("",%1-$L(%)) S:$D(%2) %3=$TR(%3," ",%2)
50 Q %3_%
51 ;
52LJ(%,%1,%2) ;Left justify
53 N %3
54 S:%1["T" %1=+%1,%=$E(%,1,%1)
55 S %3=$J("",%1-$L(%)) S:$G(%2)]"" %3=$TR(%3," ",%2)
56 Q %_%3
57 ;
58CJ(%,%1,%2) ;Center Justify
59 N %3,%4
60 S:%1["T" %1=+%1,%=$E(%,1,%1) S %3=%1-$L(%) Q:%3<1 %
61 S %3=%3\2,%4=$J("",%3+1) I $G(%2)]"" S %4=$TR(%4," ",%2)
62 Q $E(%4,1,%3)_%_$E(%4,1,%1-%3-$L(%))
63 ;
64QUOTE(%) ;Add quotes to value for concatenation
65 S %(%)=0,%=$Q(%)
66 Q $P($E(%,1,$L(%)-1),"(",2,999)
67 ;
68TRIM(%X,%F,%V) ;Trim spaces\char from front(left)/back(right) of string
69 N %R,%L
70 S %F=$$UP($G(%F,"LR")),%L=1,%R=$L(%X),%V=$G(%V," ")
71 I %F["R" F %R=$L(%X):-1:1 Q:$E(%X,%R)'=%V
72 I %F["L" F %L=1:1:$L(%X) Q:$E(%X,%L)'=%V
73 I (%L>%R)!(%X=%V) Q ""
74 Q $E(%X,%L,%R)
75 ;
76SENTENCE(%X) ;
77 ; Converts a string into proper sentence case (first letter of each sentence
78 ; upper case, all the others lower case)
79 ; Example Usage:
80 ; W $$SENTENCE^XLFSTR("HELLO WORLD!!! THIS IS A CAPITALIZED SENTENCE. (this isn't.)")
81 ; produces
82 ; Hello world!!! This is a capitalized sentence. This isn't.
83 ;
84 ; %S = string during conversion
85 ; %P = state flag (1 = next letter should be caps)
86 ; I = iteration index
87 ; C = current character
88 ;
89 N %I,%C,%S,%P
90 S %S=$$LOW(%X),%P=1
91 F %I=1:1:$L(%X) D
92 . S %C=$E(%S,%I)
93 . I %P,%C?1L S $E(%S,%I)=$$UP(%C),%P=0
94 . S:".!?"[%C %P=1
95 Q %S
96 ;
97TITLE(%X) ;
98 ; Converts a string into TITLE CASE format (first letter of each word is uppercase)
99 ; Example Usage:
100 ; W $$TITLE^XLFSTR("THIS IS CAPITALIZED. (this isn't.)")
101 ; produces
102 ; This Is Capitalized. This Isn't.
103 ;
104 ; %S = string during conversion
105 ; %P = state flag
106 ; %I = iteration index
107 ; %C = current character
108 ;
109 N %I,%C,%S,%P
110 S %S=$$LOW(%X),%P=1
111 F %I=1:1:$L(%S) D
112 . S %C=$E(%S,%I)
113 . I %P,%C?1L S $E(%S,%I)=$$UP(%C),%P=0
114 . S:%C=" " %P=1
115 . Q
116 Q %S
Note: See TracBrowser for help on using the repository browser.