Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Consider this piece of Java code
I need to do this in php
String SEPARATOR = "S39Er#T0R";
String input = "someS39Er#T0RDataS39Er#T0Rhere";
String[] val = input.split(SEPERATOR);
for (int i = 0; i < val.length; i++) {
}
I need to store the data received from file_get_contents('php://input') which returns the raw post
and then from that string I need it to split and run a for loop
Can any one suggest how to implement the same code in php ?
explode function splits a string by a string;
preg_split splits a string by a regex;
foreach construct iterates over arrays or objects;
Combination of these is pretty straightforward:
$separator = 'S39Er#T0R';
$postData = file_get_contents('php://input');
$splitPostData = explode($separator, $postData);
foreach($splitPostData as $postDataItem)
{
// do something with $postDataItem
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am unable to understand the below code so, Is there any way to write this piece of code in java (Easy Manner)?
Someone told me it is using the concept of multithreading? Is it true?
Thanks for helping me in advance!
fileTypeList.forEach( fileExtension -> parseFileInfo( (JSONObject) fileExtension ) );
This is the method for parseFileInfo:
private static void parseFileInfo(JSONObject file) {
String extension = (String) file.get("Extension");
String category = (String) file.get("Category");
String type = (String) file.get("Type");
String description = (String) file.get("Description");
String programs = (String) file.get("Programs");
}
fileTypeList.forEach( fileExtension -> parseFileInfo( (JSONObject) fileExtension ) );
For every fileExtension in fileTypeList parseFileInfo is called to perform intended task.
You can easily write a for each loop for this logic.
for(FileExtension fileExtension : fileTypeList) {
parseFileInfo((JSONObject) fileExtension)
}
// I have assumed `FileExtension` as a type of `fileTypeList` list.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
in the exercise they told if string contain 00 or 0 remove it
String rse="12+00+9+88";
String re="[0]{1,2}\\+";
String oper[]=chaine.split("[0-9]{1,2}\\+");
for(int i=1;i<oper.length;i++) {
if (oper.equals(re)) {
}
}
You may juse use String.replaceAll and use 2 regexes
(0+)\+ to remove zeros followed by a +
\+(0+), specific case when zeros are the last one, the + is before it
List<String> values = Arrays.asList(
"12+00+9+88",
"12+0+9+88",
"00+9+88",
"0+9+88",
"12+00",
"12+0"
);
for (String s : values) {
String r = s.replaceAll("(0+)\\+", "").replaceAll("\\+(0+)", "");
System.out.println(r);
}
12+9+88
12+9+88
9+88
9+88
12
12
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Ex String Param=Value1:100,Value2:2000,Value3:30000:
What is the best way in java to trim the above mentioned string format to get the First element's value?
Result should be 100 (from the above mentioned Ex string param).
Assuming you have a String e = "Value1:100,Value2:2000,Value3:30000";
Your next step would be to analyze its structure. In this case it is very simple key:value which is comma separated.
We have to split at every "," and then ":".
String[] keyValues = e.split(",");
for(String keyValue : keyValues) {
String tupel = keyValue.split(":");
// tupel[0] is your key and tupel [1] is your value
}
You can now work with this. You can add these to a map to access it by name.
Also this How to search a string of key/value pairs in Java could be worth looking at.
If you only want the first value, you can take a substring up to the first ',':
String p = "Value1:100,Value2:2000,Value3:30000:";
int firstComma = p.indexOf(',');
if(firstComma >= 0) {
p = p.substring(0, firstComma);
}
String tuple[] = p.split(":");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string Saxon Securitie/Logo/horse-logo.jpg_1413458235818 in format "A/B/C"
I want the result as C by removing "A/B/" from the above string and get a result
String C = "horse-logo.jpg_1413458235818"
Try:
String s = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
String c = s.substring(s.lastIndexOf("/") + 1);
System.out.println(c);
String filePath = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
String fileName = new File(filePath).getName();
See https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
You can use String.lastIndexOf to do that :
String path = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
int index = path.lastIndexOf("/");
String fileName = index == -1 ? null : path.substring(index + 1);
I'm not going to give you answer but you could easily use split function in java that you can learn about here. and at first split with space then split with /
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
hello I have this string that is a data table I want to test if the string contains more than _ then we are cutting the chains and in each sub string in a table row
I use talend and my input is an excel
I'm really stuck who can help me please
exemple:
JEN3030_1_2_3
JEN3030_1
JEN3030_2
JEN3030_3
Try String.split()...
String input = "JEN3030_1_2_3"; //or whatever
List<String> output = new ArrayList<String>();
String[] parts = input.split("_");
for(int i = 1; i < parts.length; i++) {
output.add(parts[0] + "_" + parts[i]);
}