Delete everything after part of a string
For example, you could do:
String result = input.split("-")[0];
or
String result = input.substring(0, input.indexOf("-"));
(and add relevant error handling)
Remove part of string after .
You just need to escape the period:
a <- c("NM_020506.1","NM_020519.1","NM_001030297.2","NM_010281.2","NM_011419.3", "NM_053155.2")
gsub("\\..*","",a)
[1] "NM_020506" "NM_020519" "NM_001030297" "NM_010281" "NM_011419" "NM_053155"
Deleting content of every string after first empty space
Assuming that there is no space in the beginning of the string.
Follow these steps-
- Split the string at space. It will create an array.
- Get the first element of that array.
Hope this helps.
str = "Example string"
String[] _arr = str.split("\\s");
String word = _arr[0];
You need to consider multiple white spaces and space in the beginning before considering the above code.
I am not native to JAVA Programming but have an idea that it has split function for string.
And the reference you cited in the question is bit complex, while you can achieve the desired thing very easily.
P.S. In future if you make a mind to get two words or three, splitting method is better (assuming you have already dealt with multiple white-spaces) else substring is better.
Remove everything after a certain character
You can also use the split()
function. This seems to be the easiest one that comes to my mind :).
url.split('?')[0]
jsFiddle Demo
One advantage is this method will work even if there is no ?
in the string - it will return the whole string.
Delete everything after 4th period in string
Use rsplit()
for the cleanest or most simple route:
s = "192.168.0.50.XXXX"
s = s.rsplit('.',1)[0]
Output:
192.168.0.50
rsplit()
Returns a list of strings after breaking the given string from right
side by the specified separator.
how to remove all the string after a word in javascript?
It can be done the following way :
var input='bla\n\nbla\n\nShare something ...\n\nbla bla bla\n<image tag></img>bla\n<image tag></img>';
var output = input.split('Share something')[0]+'Share something';
console.log(output);
How to delete everything after matching string in R?
You can just do
gsub("SsHV2L.+$", "SsHV2L", test)
Here you grab the "SsHV2L" where there is something after it and then just replace all of that with only "SsHV2L"
Related Topics
Java.Io.Filenotfoundexception: the System Cannot Find the File Specified
How to Retrieve Element Value from Soap Response Using Java
How to Do Name Validation Allowing Alphabet, Spaces and Dot in Android
How to Find the Number of Times If or Else Code Has Executed
Changing Scene When a Button Is Pressed Fxml
Javafx Column in Tableview Auto Fit Size
Array Pairwise Matching in Java Give Error Also Store Data Between Two Similar Element
Java Xmlbeans Throws Nosuchmethod Error
Spring Data Query Method With Optional @Param
Spring - Read Property Value from Properties File in Static Field of Class
How to Return a Custom Object from a Spring Data JPA Group by Query
How to Scroll to the Bottom of a Recyclerview? Scrolltoposition Doesn't Work
Delete a Line from a File Using Java
Round Off a Double While Maintaining the Trailing Zero
Custom Pagination by Array List
Jdk Tools.Jar as Maven Dependency
Jackson Polymorphism: How to Map Multiple Subtypes to the Same Class