Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Given a string "Hello". I only want all the letters after the first letter to be in my new string.
E.g.: "ello"
How could this be done?
Tried pattern matching but cant get it to work :(
Try this:
String s = "Hello";
String newS = s.substring(1); // newS is "ello"
The above will create a new string containing all the characters of the original, except the first one. See the documentation for more details.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to detect the file structure in a string.
e.g
if I have a string as /name/test/testme/2 I should be able to store it in a arraylist as different elements like {[name],[test],[testme],[2]}
String[] elements = "/name/test/testme/2".split("/");
More info can be found in the String.split() Javadoc
As Lukas pointed out, (please give him some upvoting) you should use the split method.
String[] elements = "/name/test/testme/2".split("/");
The regular expressions are not used to split strings in sections. Regular expressions are used for matching the target string with a specific generic format. In this case a boolean value indicating if the strings match is returned.
Hope I helped!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am looking for a regular expression to remove all #[x] present in a string
Where x can be any string.
For example #[title]
#\[[^\]]*\]?
As in:
String s = "asda #[asdagf] dsgfdg";
System.out.println(s.replaceAll("#\\[[^\\]]*\\]",""));
will print out:
asda dsgfdg
String original = "Hello #[world]!";
String replaced = original.replaceAll("#\\[.*?\\]", "");
// replaced = "Hello !"`enter code here`
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
For this string, 16.82080560, 96.13055810 I want to get
"String one = 16.82080560"
and
"String two = 96.13055810"
in android.
Admin that I suck in string manipulation and regex.
Please let me know how can I get such two value from a string.
String[] components = original.split(",");
If the Strings are always separated by a comma you can use String.split
For a better regex pattern see the comment from #npinti:
Minor side note, it might be better to do \\s*,\\s* instead of just ,.
Just , might cause problems should the OP wish to cast these to
floats, since the extra white space at the beginning of the second
number will most likely not be recognized as a proper number.
Another option:
String str = "16.82080560, 96.13055810";
StringTokenizer st = new StringTokenizer(str,", ");
String one = st.nextToken();
String two = st.nextToken();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this xml file from where I'm reading this string,
http://localhost:8080/sdpapi/request/10/notes/611/
My question is how can I get just the 611, which is of variable, can be 100000, for example, from this string?
Split the string
String input = "http://localhost:8080/sdpapi/request/10/notes/611/";
String output = input.split("notes/")[1].split("/")[0];
output is the value you need
What language?
Anyway, in most cases it's a syntax like:
String.substring(begin, length);
... where 'begin' is the number of the letter in the string-1. For extracting http from the above string you would write
substring(0, 4);
In case you always need the last string between the last two '/'s, you can retrieve the position of the slashes with index-functions (as stated in the answer of #Liran for example).
// EDIT: In Java the second parameter of substring is not length, but endIndex:
String s = "http://localhost:8080/sdpapi/request/10/notes/611/";
s.substring(46, s.lastIndexOf('/'));
It depends on programming language you use, but Regular Expressions should be the same in most of them:
/(\d+)\/$/
well, it depend in what language are you writing... in c# for example
string s = #"http://localhost:8080/sdpapi/request/10/notes/611/";
s.SubString(s.LastIndexOf('/'));
or
Path.GetFileName(s);
for java
new File(s).getName();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am currently trying to make use of the java string function someString.replaceAll() to find commonly used words (and, the, by, of, etc) and replace them with " ". Based on the answers to the question at Whitespace Matching Regex - Java, I produced this function call:
data.replaceAll("(?i)\\sthe\\s", " ")
However, it isnt working and I'm really not sure why. Nothing about it looks wrong based on what I've found. Please help me!
Strings are immutable!
data = data.replaceAll("(?i)\\sthe\\s", " ");