RexEx und replaceAl

Status
Nicht offen für weitere Antworten.
G

gast

Gast
habe folgenden String:
Code:
String pStr= "(([a|Af|F]4)([0-9a-fA-F]{2})([0-9a-fA-F]{4})(55[fF]{6})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{##}))";

jetzt muss ich an der stelle, wo ## steht, die länge (z.B. 22) einfügen. So soll der Strint wie folgt aussenen:

Code:
String pStr= "(([a|Af|F]4)([0-9a-fA-F]{2})([0-9a-fA-F]{4})(55[fF]{6})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{22}))";

habe wie folgt probiert:

Code:
pStr.replaceAll("##", new Integer(length).toString());

variable "length" ist vorhanden. aber, es will nicht. wie macht man so was?

danke.
 
S

SlaterB

Gast
int x = 5;
x+3;

dann ist x immer noch 5 ;)

Code:
public class Test
{
    public static void main(String[] args)
    {
        String pStr = "(blahblah{##}))";
        pStr = pStr.replaceAll("##", "22");
        System.out.println(pStr);
    }
}
 
G

gast

Gast
schamde über mich :oops: :oops: :oops:

habe den rückgabewert nicht beachtet!

danke.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen

Ähnliche Java Themen

Neue Themen


Oben