Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
So in effect the 28th character in my filename needs to "_".
/**
* reverseIt() Reverses a string.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string ("fred") input: the string to be reversed
*
* {example} reverseIt("fred") # derf
*
*/
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
/**
* anyWord() finds a word in a string based on a delimiter and the number of the word required.
* It can search forwards or backwards depending on whether the number of the word is positive or negative.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string("hello Example") input: The string need to be parsed.
*
* {param} string(" ") input: the delimiter
*
* {param} int(0) input: the number of the word to return - 0 is first occurrence -1 is the last.
*
* {example} anyWord("hello Example"," ",0) # hello
*/
@SuppressWarnings("finally")
public static String anyWord(String message, String delimiter, Integer number ) {
String returnString = null;
Integer reverseit = 0;
try {
if (number < 0) {
message = Ncl_routines.reverseIt(message);
number = -1 - number;
reverseit = 1;
}
if (delimiter.equals(" ")) {
String[] starwords = message.split (" ");
returnString = starwords;
}
if (! delimiter.equals(" ")) {
String[] starwords = message.split ("\\" + delimiter);
returnString = starwords;
}
if (reverseit == 1) {
returnString = Ncl_routines.reverseIt(returnString);
}
} catch (ArrayIndexOutOfBoundsException e) {
returnString = "";
} finally {
return returnString;
}
}
}