I have a list containing the following:
String list[]={"Team 1,Apple,Mango,Kiwi","Team 2,Mango,Kiwi,Pineapple","Team 3,Kiwi,Pineapple,Apple"};
my question is, how do you know what each team has? also how do you get the team name?
i would like to have the output:
Team 1,Team 3(Apple,Kiwi)
Team 1,Team 2(Mango,Kiwi)
Team 2,Team 3(Pineapple,Kiwi)
can someone tell me what can be done or what to do?
In order to get the values of the first string in a list of strings you can split the string by "," and put it in a list like following: String s1 [] = list[0].split(","); and then s1[0] is Team1 s1[1] is Apple etc..
You can make use of StringTokenizer to accomplish your task.
http://developer.android.com/reference/java/util/StringTokenizer.html
Related
my json is
{[{"key1":"value1","key2":"valu2"},{“ key3":"value3","key4":"valu4”}]}
How to change the above text as follows. Thank you for helping my friends
{"travel": [{"key1":"value1","key2":"valu2"},{ key3":"value3","key4":"value4}]}
Your original String is not a valid JSON for two reasons:
1 we can see some invalid quotes
2 elements inside a json object must have keys.
so assuming that your String is correct to achieve what you need in java you can do the following:
String string="{[{\"key1\":\"value1\",\"key2\":\"valu2\"},{\" key3\":\"value3\",\"key4\":\"valu4\"}]}";
StringBuilder stringBuilder=new StringBuilder(string);
stringBuilder.insert(1,"\"travel\":");
String json=stringBuilder.toString();
You just insert your key after the first character. Hope this will help.
I want to put extra value from intent to other intent. But in other intent, app get all value. Example:
mAddress.setText(" from " + address);
String put_address = mAddress.getText().toString();
editIntent.putExtra("put_address", put_address);
is it possible to cut text "from" and get only address variable ???
you can split a string like
str = "From address#dd.com";
String modified = str.replace;
now splitstr contain your split strings
splitStr[1] contains "address#dd.com"
Can also use
str.substring(str.indexOf(" ")+1);
By the way, you can use jagapathi's answer. In his example he uses regular expression.
Regular expressions can help to parse, find, cut substrings using a particular pattern. In his code he splits string by any space character.
But, imho, the simplest solution is to create a substring using this code:
'put_address.substring(7);'
use one of these solutions:
String input = put_address.trim().substring(5);
*** note: 5 is index of real address first character;
String input = put_address..split(" ")[1];
I have a .txt file which contains above 1000 words
sample city names below
Razvilka
Moscow
Firozpur Jhirka
Kathmandu
Kiev
Pokhara
Merida
Delhi
Reshetnikovo
Ciudad Bolivar
Marfino
Zhukovskiy
Reutov
Kurovskoye
etc
I would like to have these words in this format below
"Razvilka","Moscow","etc","etc"
enclosed with double quotation and with a comma in the end.I am using Notepad++.Could you mention how to do it and which software should I use it?
If you're using Notepad++, make a Search and Replace replacing
\b(\w+)\b
with
"$1",
It'll find all words and replace with them self, surrounded by quotes. You'll have to manually remove the last , if that's unwanted.
Regards
I wonder if this question is about programming, but You tagged android, regex and android studio, so I guess it is. If yes, You can simply split a string in that way:
String[] splitted = yourString.split("\\s+");
In that case, You are splitting the strings by whitespaces (this regex is also for more than one whitespace), like Your string seems to be. If You have more than one delimiter, You can do it by using the OR operator |
String[]splitted = yourString.split("-|\\.");
In that example, You are splitting the String by - and . (minus and point). The delimiter is the sign where the String is splitted by.
I have a value in a string variable. I need to take first and last letters from the string variable. Append it with xxx in between them. For example, if the string variable value is "googleuser", then i should get the output as "gxxxr". How is this made? I tried many ways, suggested by google, but still didn't find anything which is helpful to me. Can some one suggest me a way for this. I tried the charat(index) function but it returned wrong results.
You could do that using the StringBuilder:
StringBuilder s = new StringBuilder();
s.append(text.charAt(0));
s.append("xxx");
s.append(text.charAt(text.length -1));
s.toString();
You could use regexp
String s = "aaa";
s.repalceAll("(.){1}(.)+(.){1}", "$1xxx$3");
i want to create an android application that can search word in sqlite database using approximate string matching.
for example if someone misspelled the word "switch" with " swithc", the sistem will correct the word and show message "did you mean 'switch' ".
its like google that can correct wrong word. how can i do it ?
have a look at this answer
Java: how to find the most probable string in a list of strings?
you can use the way of string matching as you desire. there is also a github project for this at:
https://github.com/northpoint/blur