Modifying string on java -



Modifying string on java -

i must turn string type modified xpathes real xpathes java;

for example;

this kind of xpathes

_html_1__body_1__form_1__input_3_

should turn

/html[1]/body[1]/form[1]/input[3]

i have no idea, please help me

like lateralus said, strings immutable, can't alter these.

however, having said that, can utilize replaceall homecoming modified version of string, illustration in case:

string input = "_html_1__body_1__form_1__input_3_"; string output = input.replaceall("_(\\d+)_", "[$1]").replaceall("_", "/"); // output = /html[1]/body[1]/form[1]/input[3]

edit

as explanation of regex used in case:

this method uses 2 separate regular expressions homecoming modified string. firstly, "_(\\d+)_", looks numbers surrounded 2 underscore characters _, \\d regex short hand digit. surrounding brackets (...) capture number, can reference in replacement string.

when create first replacement, replace [$1], in here $1 refers first captured group, i.e. digit captured, , surrounds in square brackets [...]. underscores removed, these captured in expression, if not in group.

the sec replaceall phone call replaces remaining underscore characters /.

java string

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -