*** empty log message ***
[thera-pi.git] / BMIRechner / src / Tools / StringTools.java
blob2a7301e427378f8d6c51b2af3d269611d8b8ba9d
1 package Tools;
3 public class StringTools {
5 public static String EGross(String string){
6 if(string == null){
7 return "";
9 if(string.trim().equals("")){
10 return "";
13 String test = new String(string.trim());
14 String neuString = "";
15 try{
16 for(int y = 0; y < 1; y++){
19 if( (test.indexOf(" ") < 0) && (test.indexOf("-") < 0) ){
20 neuString = test.substring(0,1).toUpperCase()+
21 (test.length() > 1 ? test.substring(1).toLowerCase() : "");
22 test = new String(neuString.trim());
23 return test;
26 if(test.indexOf(" ") > -1){
27 String[] splitString = test.split(" ");
28 for(int i = 0;i < splitString.length;i++){
29 neuString = neuString +
30 (splitString[i].substring(0,1).toUpperCase())+
31 (splitString[i].length() > 1 ? splitString[i].substring(1).toLowerCase() : "");
32 neuString = neuString + " ";
34 test = new String(neuString.trim());
36 if(test.indexOf(" - ") > -1){
37 neuString = "";
38 String[] splitString = test.split("-");
39 for(int i = 0;i < splitString.length;i++){
40 neuString = neuString +
41 (splitString[i].substring(0,1).toUpperCase())+
42 (splitString[i].length() > 1 ? splitString[i].substring(1).toLowerCase() : "");
43 neuString = neuString + (i < (splitString.length-1) ? " - " : "");
45 test = new String(neuString.trim());
46 break;
48 if(test.indexOf("-") > -1){
49 neuString = "";
50 String[] splitString = test.split("-");
51 for(int i = 0;i < splitString.length;i++){
52 neuString = neuString +
53 (splitString[i].substring(0,1).toUpperCase())+
54 (splitString[i].length() > 1 ? splitString[i].substring(1).toLowerCase() : "");
55 neuString = neuString + (i < (splitString.length-1) ? "-" : "");
57 test = new String(neuString.trim());
61 if(test.indexOf("prof.") > -1){
62 neuString = test.replaceAll("prof.", "Prof.");
63 test = new String(neuString);
65 if(test.indexOf("dr.") > -1){
66 neuString = test.replaceAll("dr.", "Dr.");
67 test = new String(neuString);
69 if(test.indexOf("dres.") > -1){
70 neuString = test.replaceAll("dres.", "Dres.");
71 test = new String(neuString);
73 if(test.indexOf(" Med. ") > -1){
74 neuString = test.replaceAll(" Med. ", " med. ");
75 test = new String(neuString);
77 if(test.indexOf("Med.") > -1){
78 neuString = test.replaceAll("Med.", "med.");
79 test = new String(neuString);
82 if(test.indexOf(" Von ") > -1){
83 neuString = test.replaceAll(" Von ", " von ");
84 test = new String(neuString);
87 if(test.indexOf(" Und ") > -1){
88 neuString = test.replaceAll(" Und ", " und ");
89 test = new String(neuString);
91 if(test.indexOf(" Zu ") > -1){
92 neuString = test.replaceAll(" Zu ", " zu ");
93 test = new String(neuString);
95 if(test.indexOf(" An ") > -1){
96 neuString = test.replaceAll(" An ", " an ");
97 test = new String(neuString);
100 if(test.indexOf(" Auf ") > -1){
101 neuString = test.replaceAll(" Auf ", " auf ");
102 test = new String(neuString);
105 if(test.indexOf(" Der ") > -1){
106 neuString = test.replaceAll(" Der ", " der ");
107 test = new String(neuString);
109 if(test.indexOf(" Bei ") > -1){
110 neuString = test.replaceAll(" Bei ", " bei ");
111 test = new String(neuString);
113 if(test.indexOf(" Den ") > -1){
114 neuString = test.replaceAll(" Den ", " den ");
115 test = new String(neuString);
117 if(test.indexOf(" Die ") > -1){
118 neuString = test.replaceAll(" Die ", " die ");
119 test = new String(neuString);
121 if(test.indexOf("-Die") > -1){
122 neuString = test.replaceAll("-Die", "-die");
123 test = new String(neuString);
125 if(test.indexOf("Aok") > -1){
126 neuString = test.replaceAll("Aok", "AOK");
127 test = new String(neuString);
129 if(test.indexOf("Bkk") > -1){
130 neuString = test.replaceAll("Bkk", "BKK");
131 test = new String(neuString);
133 if(test.indexOf("Ikk") > -1){
134 neuString = test.replaceAll("ikk", "IKK");
135 test = new String(neuString);
137 if(test.indexOf("Tkk") > -1){
138 neuString = test.replaceAll("Tkk", "TKK");
139 test = new String(neuString);
141 if(test.indexOf("Dak") > -1){
142 neuString = test.replaceAll("Dak", "DAK");
143 test = new String(neuString);
145 if(test.indexOf("str.") > -1){
146 neuString = test.replaceAll(" str.", " Str.");
147 test = new String(neuString);
150 }catch(java.lang.StringIndexOutOfBoundsException ex){
151 //System.out.println(ex);
152 return ""+test;
155 return neuString.trim();
158 public static String NullTest(String string){
159 if(string==null){
160 return "";
161 }else{
162 return string;
165 public static int ZahlTest(String string){
166 if(string==null){
167 return -1;
168 }else{
169 int zahl;
170 try {
171 zahl = new Integer(string.trim());
172 }catch(NumberFormatException ex){
173 zahl = -1;
175 return zahl;
178 public static String Escaped(String string){
179 String escaped = string.replaceAll("\'", "\\\\'");
180 escaped = escaped.replaceAll("\"", "\\\\\"");
181 return new String(escaped);
183 public static String EscapedDouble(String string){
184 String escaped = string.replaceAll("\'", "\\\\\\'");
185 return new String(escaped);
187 public static String fuelleMitZeichen(String string,String zeichen,boolean vorne,int endlang){
188 String orig = string;
189 String praefi = zeichen;
190 String dummy = "";
191 String sret = "";
192 int solllang = endlang;
193 int istlang = orig.length();
194 int differenz = solllang - istlang;
195 if(differenz > 0){
196 for(int i = 0; i < differenz;i++){
197 dummy = dummy+praefi;
199 if(vorne){
200 sret = dummy+orig;
201 }else{
202 sret = orig+dummy;
204 }else{
205 sret = new String(orig);
207 return sret;