remy boys remy boys - 1 year ago 45
Android Question

transforming String and getting the Specified Value Java (Android)

well apologise at first because its more like asking for help then asking a question , so am a noob in Android development and i want to write a function which i've written for iOS in swift , so if anybody can help me with this then it'll be great :

i want to convert a String from String1 = "Guardians Of the Galaxy(G.T.G)" into
String2 = "GTG" all i want to is to get the value which is inside the brackets and remove the

from it and also if there's any space within them

here's how i do it in Swift maybe it'll help to understand

if the
spaceLessFullForm = "Catch Me if You Can"

let SpaceLessFullForm = Fullform.condensedWhitespace
let delimiters: NSCharacterSet = NSCharacterSet(charactersInString: "()")
var splitString: [AnyObject] = SpaceLessFullForm.componentsSeparatedByCharactersInSet(delimiters)
let substring: String = splitString[1] as! String
let dotLessString = substring.stringByReplacingOccurrencesOfString(".", withString: "")
let upperCaseFirstCharcters = dotLessString.stringByReplacingOccurrencesOfString(" ", withString: "")

then my
upperCaseFirstCharcters = "CMIUC"

Answer Source

Try this way..

String kek = "Guardians Of the Galaxy(G.T .G . V)";
int fInd = kek.indexOf("(") + 1;
int lInd = kek.indexOf(")");
String kek1 = kek.substring(fInd, lInd);
String kek2 = kek1.replace(".", "").replace(" ", "");
Toast.makeText(getApplicationContext(), kek2, Toast.LENGTH_SHORT)

Result will be : GTGV