모든 쉼표를 java의 큰 따옴표 안에있는 하나의 특수 문자 (예 : "#")로 바꾸려고합니다. 내가 할 문자열의 첫 번째 차례 나오는 찾기 위해 위의 코드를 사용하여java Regex를 사용하여 문자열의 쉼표를 문자열로 바꾸기
public class Str {
public static void main(String[] args) {
String line="\"Lee, Rounded, Neck, Printed\",410.00,300.00,\"Red , Blue\",lee";
String lineDelimiter=",";
String templine=line;
if(templine!=null && templine.contains("\""))
{
Pattern p=Pattern.compile("(\".*?"+Pattern.quote(lineDelimiter)+".*?\")");
Matcher m=p.matcher(templine);
if(m.find())
{
for (int i = 1; i <= m.groupCount(); i++) {
String Temp=m.group(i);
String Temp1=Temp;
Temp=Temp.replaceAll("(,)", " ## ");
line=line.replaceAll(Pattern.quote(Temp1),Pattern.quote(Temp));
}
}
}
}
}
:
String line="\"Lee, Rounded, Neck, Printed\",410.00,300.00,\"Red , Blue\",lee";
출력 : 내가 시도
"Lee# Rounded# Neck# Printed",410.00,300.00,"Red # Blue",lee
이 아래
은 문자열입니다 두 번째가 아닌 따옴표 안의 내용 ("Red, Blue").
을 당신은하지 않습니다 Regex가 간단한 문자 교체를 할 필요가 있으며 Regex를 사용하는 것도 어렵지 않습니다. 어떤 문제가 발생 했습니까? – Matthew
포인트는 "큰 따옴표 안에"입니다. 그럼에도 불구하고 무엇을 시도 했습니까? –
CSV 라이브러리 사용을 고려 했습니까? –