"byT1r1nYKDYlWrBwnSCamRCBnPzvEKckMamAIeMg4sXpZZ3PyeJvVynxptc7QByA3CM54eGNK9MthDmuoS1Hmfdq7PPshqnko2007sPvif5ipj9sBuV1krcvbheDNSFZSUgWwCSJ7NW8AJs0pnzdfdgOmWduNvUFGMJy1t4TCqXeDDKIAd5aVGs4wuaM XZ8AibK63B1fNLYlc60fCwI4pDYBcewckeJZzJ7y H2hRMlMc3 1ktQ1szu/3LPFHYIYbpnWdDH8ork0OZKK49/MOrwWLalpMbsXys892s5njnDlxzySs5EDoqfihzT JTJre7ywGamR3k/dl1gzx2dMtpKpKHAIfP4qaIfPI2A6C5PSHuuG5e9TGDUbtktm7zgs a4KJiNi9Phf/zZjIiwk46Z 8 mCYuDzGeCJmDp3AX9oU pW O2J5VpaRAZScs"请用replaceAll将字符串里面不能呗Base64编码的非法字符去除
时间: 2023-11-30 14:02:02 浏览: 91
Unity3D屏幕截图写法1
可以使用以下代码将字符串中不能被 Base64 编码的非法字符去除:
```
String str = "byT1r1nYKDYlWrBwnSCamRCBnPzvEKckMamAIeMg4sXpZZ3PyeJvVynxptc7QByA3CM54eGNK9MthDmuoS1Hmfdq7PPshqnko2007sPvif5ipj9sBuV1krcvbheDNSFZSUgWwCSJ7NW8AJs0pnzdfdgOmWduNvUFGMJy1t4TCqXeDDKIAd5aVGs4wuaM XZ8AibK63B1fNLYlc60fCwI4pDYBcewckeJZzJ7y H2hRMlMc3 1ktQ1szu/3LPFHYIYbpnWdDH8ork0OZKK49/MOrwWLalpMbsXys892s5njnDlxzySs5EDoqfihzT JTJre7ywGamR3k/dl1gzx2dMtpKpKHAIfP4qaIfPI2A6C5PSHuuG5e9TGDUbtktm7zgs a4KJiNi9Phf/zZjIiwk46Z 8 mCYuDzGeCJmDp3AX9oU pW O2J5VpaRAZScs";
str = str.replaceAll("[^a-zA-Z0-9+/=]", "");
```
这里使用了正则表达式 `[^a-zA-Z0-9+/=]`,表示匹配除了 Base64 编码允许的字符之外的所有字符,并将其替换为空字符串。
阅读全文