Java替换为null

时间:2017-09-15 15:22:59

标签: java android

下面我在变量img[0]中保留了一个图片网址,我希望将其替换为字符串src="x"中找到的所有content_val。然后将包含在replacedStr[0]中。

但是,在使用replacedStr[0]时,我只会获得null

final String[] img = new String[count];
final String[] replacedStr = new String[1];

StorageReference filepath = mStorage.child("Blog_Image").child(mImageURi.getLastPathSegment());

for(int i =0; i < count; i++) {

    final int index = 0;
    StorageReference filepath1 = mStorage.child("Blog_Image").child(mImageURi.getLastPathSegment() + random());

    filepath1.putFile(mImageURi).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

            final Uri downlaodUrl = taskSnapshot.getDownloadUrl();
            String b = downlaodUrl.toString();
            img[0] = b;

            //find first src=content
            String imgSrc="found";
            Pattern pattern = Pattern.compile("<img(.+)src=\"[^\"]+\"(.*)>");
            Matcher matcher = pattern.matcher(content_val);

            replacedStr[0] = img[0];

            //replace with URL
            if (matcher.find()) {
                imgSrc = matcher.group(1);
                replacedStr[0] = content_val.replaceAll("src=\"(.*?)\"", img[0]);

0 个答案:

没有答案