How do I convert string builder to string array in Android? [duplicate] - android

This question already has answers here:
StringBuilder to Array of Strings how to convert
(2 answers)
Closed 6 years ago.
I have a string builder in Android which is filled with data from a database, and I want to display that data using a list view. For that I want to covert string builder into an array of strings. Can somebody help me in this conversion, or suggest to me some other technique.

Here you can find Link
tempArray = sb.toString().split("ABCABC"); will split the string and return an array of strings for each line.

Try this :
String sbString = sb.ToString();
String[] ary = "abc".split("TABTAB");

Related

How to split a string seperated where characters are seperated by , to array in kotlin? [duplicate]

This question already has answers here:
How could I split a String into an array in Kotlin?
(6 answers)
Closed 1 year ago.
val sharedPreferences90 =
getSharedPreferences("sharedPrefs90", Context.MODE_PRIVATE)
val savedString90: String? =
sharedPreferences90.getString("STRING90","null") `
Here my String is company1,company2,company3. I would like to convert it to array. How do I do that?
val result = "company1,company2,company3".split(",").toTypedArray()

How can i get sub string that is after three #? [duplicate]

This question already has answers here:
How to get the last characters in a String in Java, regardless of String size
(11 answers)
Closed 4 years ago.
I have a string "Century Gothic#12,75#True#FFFFFFFF" and i would be able to retrive just the string "FFFFFFFF" so how can i use substring to get the string after the third #? or can i just start in someway to substring the String from the end?
Try this:
String s = "Century Gothic#12,75#True#FFFFFFFF";
String[] parts = s.split("#");
//parts[2] = "FFFFFFFF"

How to convert a string mathematical expression into a BigInteger? [duplicate]

This question already has answers here:
How to evaluate a math expression given in string form?
(26 answers)
Closed 7 years ago.
A part of the goal in my app is to receive a mathematical expression (e.g. 1 + 1) by string, and convert it to a BigInteger.
My goal is to have an equivalent to:
BigInteger result = new BigInteger("1+1");
// This will throw an exception of invalid BigInteger
Also, ScriptEngineManager class isn't available for Android.
I still cannot find a way to achieve my goal.
Thanks a lot for helping!
You can try :
//If you have to parse only the result
String result = "2";
BigInteger.valueOf(Long.valueOf("2");
//If you have to parse the whole operation
String result = "1+1";
//create an algo to extract each 1 and determine operation
BigInteger bigIntUn = new BigInteger("1");
BigInteger bigIntAnotherUn = new BigInteger("1");
//you have add (+), min(-), multiply(*) (etc...)
bigIntUn.add(bigIntAnotherUn);

list string to single string [duplicate]

This question already has answers here:
Java: convert List<String> to a join()d String
(23 answers)
Closed 7 years ago.
I have a situation in which I want to convert a List<String> to a single String and with commas
PS : I'm using RootTools library for command and I wanna execute a
Busybox --list command
Just iterate over your list and add elements as they come to a String.
This is one way of doing it but there are others.
List<String> myList ;
String result = "";
//...
for (String tmp : myList) {
result += tmp+","
}

I want to extract strings from data [duplicate]

This question already has answers here:
How do I split a string in Java?
(39 answers)
Closed 8 years ago.
I have data with repeating pattern '###'.I want to extract all strings between this pattern.
The data is like -
son###can###e###nick###54###
how can i get all data between the pattern '###'.
try this:
String patternString = "###";
Pattern pattern = Pattern.compile(patternString);
String[] split = pattern.split(text);
You can use Scanner with "###" delimiter.
Scanner in = new Scanner("son###can###e###nick###54###");
in.useDelimiter("###");
while(in.hasNext)
String x = in.next();
//Do something with x;
x will hold everything between ###. You can easily store them in an Array inside the loop or use them anyway you like.
Try this:
String str = "son###can###e###nick###54###";
String newStr = str.replaceAll("[#]+", "");
or you can separate all world via
String rem = "###";
Pattern pattern = Pattern.compile(rem);
String[] splitarr = pattern.split(text);
for(int i=0;i<aplitarr.length();i++)
{
String word=aplitarr[i].ToString();
}
Hope this may help you!
try,
String[] separated = CurrentString.split("###");
separated[0]; // this will contain "son"
separated[1]; // this will contain "can"
or
StringTokenizer tokens = new StringTokenizer(CurrentString, "###");
String first = tokens.nextToken();// this will contain "son"
String second = tokens.nextToken();// this will contain "can"

Categories

Resources