Eu tenho uma string que eu quero remover palavras específicas que contém determinada palavra dentro deles.
por exemplo: String str = "Create_DateTime, Hello, DateTime, Before"
cada palavra que contém a palavra 'Data' deve ser removido para após a remoção vamos obter a seguinte cadeia após a remoção será:Hello,Before
Eu tenho essa string: Expected_Start_DateTime,Metrics_Count,Device_UID,Command_Name,Command_Interval,Start_DateTime,Instance_UID,Execution_Date,Metrics_Size_KB,End_DateTime,Tags_Countfrom command_execution
e eu consegui remover todas as palavras desnecessárias agora minhas cordas se parece com isso: ,Metrics_Count,Device_UID,Command_Name,Command_Interval,,Instance_UID,,Metrics_Size_KB,,Tags_Countfrom command_execution
Eu quero remover o '' antes ou depois da palavra
Este é o código que usei para fazer o acima:
String str1 = str.replaceAll("\\w*Date\\w*","");
string original: Expected_Start_DateTime,Metrics_Count,Device_UID,Command_Name,Command_Interval,Start_DateTime,Instance_UID,Execution_Date,Metrics_Size_KB,End_DateTime,Tags_Countfrom command_execution
Esperado:
Metrics_Count,Device_UID,Command_Name,Command_Interval,,Instance_UID,Metrics_Size_KB,,Tags_Countfrom command_execution
Real: ,Metrics_Count,Device_UID,Command_Name,Command_Interval,,Instance_UID,,Metrics_Size_KB,,Tags_Countfrom command_execution
Uma abordagem seria utilizar fluxos java
String str = "Expected_Start_DateTime,Metrics_Count,Device_UID,Command_Name,Command_Interval,Start_DateTime,Instance_UID,Execution_Date,Metrics_Size_KB,End_DateTime,Tags_Countfrom command_execution";
String result = Stream.of(str.split(","))
.filter(word -> !word.contains("Date"))
.collect(Collectors.joining(","));