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

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -