java - Split a string based on pattern and merge it back -


i need split string based on pattern , again need merge on portion of string.

for ex: below actual , expected strings.

string actualstr="abc.def.ghi.jkl.mno"; string expectedstr="abc.mno"; 

when use below, can store in array , iterate on back. there anyway can done simple , efficient below.

string[] splited = actualstr.split("[\\.\\.\\.\\.\\.\\s]+"); 

though can acess string based on index, there other way easily. please advise.

i use replaceall in case

string actualstr="abc.def.ghi.jkl.mno"; string str = actualstr.replaceall("\\..*\\.", "."); 

this replace first , last . .

you use split

string[] parts = actualstring.split("\\."); string str = parts[0]+"."+parts[parts.length-1]; // first , last word 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -