antsi klando wrote:how to split it into 3 different strings as shown above?
antsi klando wrote:how to split it into 3 different strings as shown above?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jim Pouwels wrote:
antsi klando wrote:how to split it into 3 different strings as shown above?
This is called "Negative Lookahead and Lookbehind".
What you'r basically saying here is: Take all characters that are a - (dash), except the ones that are preceded or followed by a whitespace (\s).
antsi klando wrote:string[0] = "abc"
string[1] = "def - ghi - jkl"
string[2] = "mno"
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
antsi klando wrote:also pqr separately
the condition is that every string should be separated except for the pattern "abc - def - gfh -..........".there should not be any white spaces in between the string.Only then the split operation should be performed
antsi klando wrote:Oh jim thank you so much.I could not try your method at first.It worked .thanks a lot
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
antsi klando wrote:Oh jim thank you so much.I could not try your method at first.It worked .thanks a lot
Yes, but do you understand why it works? That's the most important thing - otherwise you'll be back with a similar question next time you have a problem.
Winston
This is called "Negative Lookahead and Lookbehind".
What you'r basically saying here is: Take all characters that are a - (dash), except the ones that are preceded or followed by a whitespace (\s).
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Wouldn't you technically need a negative lookbehind and a negative lookahead? Your regex is using two lookbehinds. It may work (haven't tested) but it just looks wrong to me.
Jim Pouwels wrote:
Winston Gutkowski wrote:
antsi klando wrote:Oh jim thank you so much.I could not try your method at first.It worked .thanks a lot
Yes, but do you understand why it works? That's the most important thing - otherwise you'll be back with a similar question next time you have a problem.
Winston
As I said earlier:
This is called "Negative Lookahead and Lookbehind".
What you'r basically saying here is: Take all characters that are a - (dash), except the ones that are preceded or followed by a whitespace (\s).
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |