Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.telerikacademy.core.strings;
- @SuppressWarnings("StringConcatenationInLoop")
- public class StringHelpers {
- public static String abbreviate(String source, int maxLength) {
- //Koko
- return null;
- }
- /** Method return string with capitalized first element.
- *
- * @param source Get string.
- * @return string String.
- *
- * @author Pavel Milanov
- */
- public static String capitalize(String source) {
- String result = "" ;
- if (source.length() != 0){
- result = source.substring(0,1).toUpperCase() + source.substring(1);
- }
- return result;
- }
- /**
- * Concatenates string1 to the end of string2.
- *
- * @param string1 String - The left part of the new string
- * @param string2 String - The right part of the new string
- * @return String - A string that represents the concatenation of string1 followed by string2's characters
- *
- * @author Teodora Georgieva
- */
- public static String concat(String string1, String string2) {
- StringBuilder sb = new StringBuilder();
- sb.append(string1);
- sb.append(string2);
- return sb.toString();
- }
- public static boolean contains(String source, char symbol) {
- String temp = symbol + "";
- if (source.contains(temp)){
- return true;
- }else {
- //Acho
- return false;
- }
- }
- public static boolean endsWith(String source, char target) {
- //Galio
- return false;
- }
- public static int firstIndexOf(String source, char target) {
- //Koko
- return 0;
- }
- /** Method that find the last index of searched char in string.
- *
- * @param source Get a String.
- * @param symbol Get character.
- * @return integer
- *
- * @author Pavel Milanov
- */
- public static int lastIndexOf(String source, char symbol) {
- int lastIndex = -1;
- for (int i = 0; i < source.length(); i++) {
- if (source.charAt(i) == symbol) lastIndex = i;
- }
- return lastIndex;
- }
- /**
- * Pads string on the left and right sides if it's shorter than length.
- *
- * @param source String - The string to pad
- * @param length int - The length of the string to achieve
- * @param paddingSymbol char - The character used as padding
- * @return String The padded string
- *
- * @author Teodora Georgieva
- */
- public static String pad(String source, int length, char paddingSymbol) {
- StringBuilder sb = new StringBuilder();
- int counter = 0;
- int copy = 0;
- while(length > source.length() && length - source.length() != 1) {
- counter++;
- copy++;
- length -= 2;
- } while (counter > 0) {
- sb.append(paddingSymbol);
- counter--;
- }
- sb.append(source);
- while (copy > 0) {
- sb.append(paddingSymbol);
- copy--;
- }
- return sb.toString();
- }
- public static String padEnd(String source, int length, char paddingSymbol) {
- int repeatingLenght = length - source.length();
- String padEnd = paddingSymbol + "";
- for (int i = 0; i < repeatingLenght; i++) {
- source += padEnd;
- }
- //Acho
- return source;
- }
- public static String padStart(String source, int length, char paddingSymbol) {
- //Galio
- return null;
- }
- public static String repeat(String source, int times) {
- //Koko
- return null;
- }
- /** This method return reversed string.
- *
- * @param source Get String.
- * @return string
- *
- * @author Pavel Milanov
- */
- public static String reverse(String source) {
- StringBuilder sb = new StringBuilder(source);
- return String.valueOf(sb.reverse());
- }
- public static String section(String source, int start, int end) {
- StringBuilder sb = new StringBuilder();
- for (int i = start; i <= end; i++) {
- sb.append(source.charAt(i));
- }
- return sb.toString();
- }
- public static boolean startsWith(String source, char target) {
- //Ira
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement