I have a string like this:
"o1 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467"
How do I extract only "o1 1232.5467"
?
The number of characters to be extracted are not the same always. Hence, I want to only extract until the second space is encountered.
Explanation of the formula:FIND("#",SUBSTITUTE(A2," ","#",2))-1: The FIND function will get the position of the # character within the text string returned by the SUBSTITUTE function, subtracting 1 to get the position before the second space character in text.
You can quickly extract the text before space from the list only by using formula. Select a blank cell, and type this formula =LEFT(A1,(FIND(" ",A1,1)-1)) (A1 is the first cell of the list you want to extract text) , and press Enter button.
The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters. The substr() method does not change the original string. To extract characters from the end of the string, use a negative start position.
A straightforward approach would be the following:
string[] tokens = str.Split(' '); string retVal = tokens[0] + " " + tokens[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With