1.javaçreplaceFirst
javaçreplaceFirst
æ¥éçè¡ä½ å¯ä»¥è·è¿å»çä¸æºç ï¼
å®çæºç æ¯è¿æ ·çï¼
int cursor = 0;
char nextChar = replacement.charAt(cursor);
if (nextChar == '\\') {
cursor++;
nextChar = replacement.charAt(cursor);
result.append(nextChar);
cursor++;
å ¶ä¸replacement为"\\",码分自适应问答源码å¼å§è¿ä¸ªnextChar ä¼å¾å°æ¯'\'ï¼å ¶å®æ¯'\\'å®==â\\âï¼è¿å ¥æ¡ä»¶ï¼å次æ§è¡
replacement.charAt(1)çæ¶åæ¥éãå 为å符串"\\".length()æ¯1ï¼æ以è¶çäºãä½ æ³æ¿æ¢æ"\"éè¦æ¹æSystem.out.println("?".replaceFirst("\\?", "\\\\"));
2024-11-25 09:50
2024-11-25 09:34
2024-11-25 09:23
2024-11-25 08:44
2024-11-25 08:24
2024-11-25 07:18