Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* StringManipulate
- * <Description>
- * Various string manipulation methods.
- *
- * <Usage>
- * %javac StringManipulate.java
- * %java String Manipulate Butties
- * 1
- * BUTTIES
- * seittuB
- *
- * %java StringManipulate 1 Butties.jpg
- * .jpg
- *
- * <References>
- * CIS-201L Dr. Sloan Lab 8
- * @author
- * Dan Latham
- * @version 0.0.1
- *
- */
- public class StringManipulate
- {
- //Returns occurence of letter e in string
- public static int occurrence(String string)
- {
- int count = 0;
- int leng = string.length();
- char[] str = new char[leng];
- string.getChars(0,leng, str, 0);
- for (int i = 0; i < leng; i+=1)
- {
- if (str[i] == 'e') count+=1;
- }
- return count;
- }
- //Returns string as STRING
- public static String upper(String string)
- {
- return string.toUpperCase();
- }
- //Returns string as gnirts
- public static String reverse(String string)
- {
- int leng = string.length();
- int counter = 0;
- char[] str = new char[leng];
- char[] str_new = new char[leng];
- string.getChars(0,leng, str, 0);
- for (int i = leng-1; i >= 0; i-=1)
- {
- str_new[counter] = str[i];
- counter+=1;
- }
- String basic = "";
- for (int i = 0; i < leng; i +=1)
- {
- basic += str_new[i];
- }
- return basic;
- }
- //Returns file ext of file.jpg as .jpg
- public static String filext(String string)
- {
- int leng = string.length();
- char[] str = new char[leng];
- String stringext = "";
- string.getChars(0,leng, str, 0);
- int i = leng-1;
- while (i >= 0)
- {
- stringext += str[i];
- //System.out.println(stringext);
- if (str[i] == '.')
- {
- i = -1;
- return reverse(stringext);
- }
- i -= 1;
- }
- return "No File Extension Found in Filename";
- }
- public static void main(String[] args)
- {
- try
- {
- Integer.parseInt(args[0]);
- String c = args[1];
- System.out.println(filext(c));
- }
- catch (NumberFormatException j)
- {
- System.out.println(occurrence(args[0]));
- System.out.println(upper(args[0]));
- System.out.println(reverse(args[0]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment