Skip to content
Snippets Groups Projects
Commit bc2470dc authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #116 failed with stages
in 18 seconds
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
package de.itstall;
public class Main {
public static void main(String[] args) {
String strText = " Mein23 Text23423411 ";
System.out.println("digitCount:\t\t\t" + digitCount(strText));
System.out.println("stringReverse:\t\t|" + stringReverse(strText) + "|");
System.out.println("lTrim:\t\t\t\t|" + lTrim(strText) + "|");
System.out.println("rTrim:\t\t\t\t|" + rTrim(strText) + "|");
System.out.println("trim:\t\t\t\t|" + trim(strText) + "|");
System.out.println("subStringCount:\t\t" + subStringCount(strText, "2"));
}
/**
* Counts digits in strText
* @param strText : String
* @return int
*/
public static int digitCount(String strText) {
int iReturn = 0;
for(int i = 0; i < strText.length(); i++) {
char c = strText.charAt(i);
if(c < '0' || c > '9') continue;
iReturn++;
}
return iReturn;
}
/**
* Reverses a String
* @param strText : String : Text to reverse
* @return String
*/
public static String stringReverse(String strText) {
String strReturn = "";
char[] cText = strText.toCharArray();
for(int i = cText.length - 1; i >= 0; i--) {
strReturn += String.valueOf(cText[i]);
}
return strReturn;
}
/**
* Removes leading spaces
* @param strText : String
* @return String
*/
public static String lTrim(String strText) {
String strReturn = "";
int iTemp = 0;
char[] cText = strText.toCharArray();
boolean checkForWhitespace = true;
for(char i : cText) {
if(Character.isWhitespace(i) && checkForWhitespace) {
iTemp++;
}
else {
checkForWhitespace = false;
strReturn += String.valueOf(i);
}
}
return strReturn;
}
/**
* Removes last spaces
* @param strText : String
* @return String
*/
public static String rTrim(String strText) {
String strReturn = "";
int iFounds = 0;
char[] cText = strText.toCharArray();
boolean checkForWhitespace = true;
for(int i = cText.length; i > 0; i--) {
if (Character.isWhitespace(cText[(cText.length - i)]) && checkForWhitespace) {
iFounds++;
} else {
checkForWhitespace = false;
}
}
strReturn = strText.substring(0, strText.length() - iFounds);
return strReturn;
}
/**
* removes leading and last spaces
* @param strText : String
* @return String
*/
public static String trim(String strText) {
String strReturn = "";
strReturn = rTrim(strText);
strReturn = lTrim(strReturn);
return strReturn;
}
/**
* Counts search in given String
* @param strText
* @return
*/
public static int subStringCount(String strText, String strSearch) {
int iReturn = 0;
if(0 != strSearch.length()) {
for(int i = strText.indexOf(strSearch, 0); i != -1; i = strText.indexOf(strSearch, i +1)) {
iReturn++;
}
}
return iReturn;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment