I'm actually making an app in which I have a text area where the user can write in my little "language", nothing hard, the user can write the following lines:
game:
i>5;
i<8;
player:
name=Player 1;
So I concatenate it, lower case it, which gives me the following string: "game:i>5;i<8;player:name=player1;"
Which must give me here two Request objects,
new Request("game", "i>5;i<8")
new Request("player", "name=player1");
Here's an example below
String string = "ygu:tezr;tt;:zertrtrr.etrvz1;tzej:j;ii;,k;i,:kik,;:k:,;ab:";
String part1, part2;
ArrayList<Request> list = new ArrayList<Request>();
/*while(?){
part1 = ?
part2 = ?
list.add(new Request(part1, part2));
}*/
Thanks in advance! :D
If this is the standard format that you mentioned above then you can use following code to get the data -
String s = "game:i>5;i<8;player:name=player1;";
String[] requests = s.split(";");
System.out.println(requests[0].split(":")[0]+" "+requests[0].split(":")[1]+";"+requests[1]);
System.out.println(requests[2].split(":")[0]+" "+requests[2].split(":")[1]);
This is just to give you an idea on how you can break the string.
This what I get as an output when I run the above code -
Output
game i>5;i<8
player name=player1
Related
I am quite new to this, and I am struggling with one issue.
In Java Compute Node, through IIB, I am checking if one field has one or more values, and for each additional value I am creating a new duplicate message, except for value, these additional values are overriding.
This is working fine as a expect, see example:
Input :...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>1111111;22222222;333333333</shipper_reference_hu></root>
Modified message 1:...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>1111111</shipper_reference_hu></root>
Modified message 2:..
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>22222222</shipper_reference_hu></root>
Modified message3 :...
</leg_flight_no><lineNumber>2</lineNumber><shipper_name>BMW AG</shipper_name> <shipper_reference_hu>333333333</shipper_reference_hu></root>
But I am struggling to propagate this message out from the Java Compute node. I understand that I cant propagate messages of type String, so I am trying to parse this as a MbMessageAssemble outAssemble. This is my code:
String newMessage = inData.replace(wholeValues, outData); // replace one value with another
MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outMessage);
copyMessageHeaders(inMessage, outMessage);
MbElement outRoot = outMessage.getRootElement();
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
MbElement outBodyEl2 = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", newMessage.getBytes());
alt.propagate(outAssembly);
But this is propagate an empty message, so the newMessage is not parsed to outAssembly. Can anybody with this experience help me with this?
I figured it out. For future, here is your answer
String newMessage = "this is some test";
MbMessage outMessage=new MbMessage();
outMessage.getRootElement().createElementAsLastChild(MbBLOB.PARSER_NAME).createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", newMessage.getBytes());
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outMessage);
out.propagate(outAssembly);
I'm new to Java and I'm trying to create a poll system using PircBot.
So far my code is this:
if (message.startsWith("!poll")) {
String polly = message.substring(6);
String[] vote = polly.split(" ");
String vote1 = vote[0];
String vote2 = vote[1];
}
Which splits the strings so that someone can type !poll "option1 option2" for example and it will be split into vote1 = option1 and vote2 = option2.
I'm kind of lost from here. Am I even heading in the right direction for creating a voting system?
I figure that I'd have a separate statement as follows.
if (message.equalsIgnoreCase("!vote " + option1))
But I'm not sure where to go with that either.
I'm currently working on a jsp script that gets a path which I want split at the backslashes. Now my code doesn't seem to work. I think it's connected to the single backslashes in the path. The problem is I can't change them as the jsp will retrieve them from somewhere else...
Any suggestions what might be the reason?
<Property>
<% String testsetPath = "..\test\subfolder\version\folder\folder2";
String field = "testset";
String container[] = testsetPath.split("\\\\");
int sub = 0;
if(field.equals("testset")){
sub = 2;
}
else if (field.equals("testplan")){
sub = 1;
}
String output = container[container.length - sub];
%>
<availableValues>
<value><%= output%></value>
<displayName>Test</displayName>
<description>Test</description>
</availableValues>
Is it because you have not escaped the slashes in "testsetPath"?
String testsetPath = "..\\test\\subfolder\\version\\folder\\folder2";
String container[] = testsetPath.split("\\");
If want this to work cross-platform, you might want to do...
String container[] = testsetPath.split(File.separator);
I have a source code from a website where textmessages start with "< h2 >" and end with "< /h2 >". In my app, I read the source code and make it into a string. Now I want to read only the messages, and have tried with this:
returned = get.getInternetData("http://blablabla.com");
int start = returned.indexOf("<h2>") + 4;
int end = returned.indexOf("</h2>");
String message = returned.substring(start, end);
The problem is that I only get the very first message! My idea was to use a scanner object and do something like
while (scan.hasNext("<h2>")) {
}
But there are no get-methods from the scanner. How can read all the messages from the source code?
you should do something like this:
while (returned.indexOf("<h2>", lastIndex)!=-1) {
....
do your thing
...
increment lastIndex
}
Using Jsoup you can do this:
Document doc = Jsoup.connect("http://blablabla.com").get();
Elements h2Tag = doc.select("h2");
ArrayList<String> messages = new ArrayList<String>();
for(Element mess: h2Tag){
messages.add(mess.text());
}
Ok I have not done a very good job explaining my problem so here goes revised a few times.
I have a Survey, The Survey Produces an Integer Number. I Convert this Number into a String File name Which relates to a Preset String stored in my resources. Based on the choices made on the questions a different string is required at the end.
This code generates the desired command line; R.string.c####
int Q1 = question1.getmCounter();
int Q2 = question2.getmCounter();
int Q3 = question3.getmCounter();
int Q4 = question4.getmCounter();
int qTotal = Q1 + Q2 + Q3 + Q4;
String Test5 = "R.string.c" + qTotal;
And This code is inside onCreate to generate the content for the TextView.
textOut = (TextView) findViewById(R.id.ChmpNametxt);
textOut.setText(Test5);
Now my concept was that it would read Test5 as "R.string.c####" and load the desired string. It does not do this and i would like to know how i can get the contents of Test5 into a commandline.
Hope someon can help me im malting..
Thanks in Advance
-Chris
You got the correct answer here already: Creating Strings than can be used as Filepath - Eclipse / Android
In your case:
String stringId = "c" + qTotal; //note: not the same as what you did with your Test5
int resId = getResources().getIdentifier(stringId, "string", getPackageName());
textOut.setText(resId);
Or are we misunderstandig your use of the word "commandline"?
You need to get the reosurce id for your text, this code gets the resource id for you:
ContextWrapper cw = this.getContext();// how you get this can be different, but you need a ContextWrapper from somewhere to use.
int resId = cw.getResources().getIdentifier("c" + qTotal, "string", cw.getPackageName());
Then you can use textOut.setText with the resId variable as the parameter.