[SOLVED] Replace in a string quote and space

Hi

the voice command is confused in case that a string which uses a quote.

Example : if the command “i didn’t” is sent

see below the logs

Logs:

2018-07-01 22:39:23.374 [ome.event.ItemCommandEvent] - Item 'VoiceCommand ' received command I didn ' t
2018-07-01 22:39:23.410 [vent.ItemStateChangedEvent] - VoiceCommand changed from  to I didn ' t

Rules:

rule "VoiceCommand"
when
    Item VoiceCommand received command
then

	var String newscene= receivedCommand.toString.toLowerCase
	logInfo("Scenario", "1-newscene :"  + newscene)	
	newscene =newscene.replace('é','e')
	newscene =newscene.replace('é','e')
	newscene =newscene.replace('î','i')
	
	logInfo("Scenario", "2-newscene :"  + newscene)	
end 

Items:

String VoiceCommand       "VoiceCommand"        

How can i replace the space/quote/space to a quote ?

Please show your rules and items

1 Like

I will make it later but it’s The just voice command string

From, the microphone in the Android application, it will get the input “je t’appelle” as je t ’ appelle

yourItem.replace(" ’ ", “’”)

thanks but a string is not enclosed by double quotes

Example :newscene =newscene.replace(‘î’,‘i’)

i have updated the first post.

Thanks!!!

Why you don’t try it?

I tried. I got an error even saving the file

Beware of the funny quotes:

yourItem.replace(" ’ ", "’")

It do not work

2018-07-03 10:44:58.354 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'scenario.rules' has errors, therefore ignoring it: [820,5]: mismatched input '<EOF>' expecting '}'

image

I think that all examples above use double quotes ""
it seems that you used single quotes ''
did you try with "" ?

Also, is your rules file containing 820 lines?
when trying to debug stuff, it’s better to isolate them. Put the rule in a new file and based on the log entry pin point the error.

You need to use double quotes "
Can you post the complete rule file s’il te plaît?

1 Like
rule "VoiceCommand"
when
    Item VoiceCommand received command
then
	var String newscene= receivedCommand.toString.toLowerCase
	logInfo("Scenario", "1-newscene :"  + newscene)
	newscene =newscene.replace("’","'")
	logInfo("Scenario", "2-newscene :"  + newscene)
	newscene =newscene.replace("'","´")
	logInfo("Scenario", "3-newscene :"  + newscene)
	newscene =newscene.replace("´","`")
	logInfo("Scenario", "4-newscene :"  + newscene)
	newscene =newscene.replace("`","’")
	logInfo("Scenario", "5-newscene :"  + newscene)
end
2018-07-03 10:17:51.389 [INFO ] [ipse.smarthome.model.script.Scenario] - 1-newscene :i didn’t
2018-07-03 10:17:51.394 [INFO ] [ipse.smarthome.model.script.Scenario] - 2-newscene :i didn't
2018-07-03 10:17:51.398 [INFO ] [ipse.smarthome.model.script.Scenario] - 3-newscene :i didn´t
2018-07-03 10:17:51.403 [INFO ] [ipse.smarthome.model.script.Scenario] - 4-newscene :i didn`t
2018-07-03 10:17:51.407 [INFO ] [ipse.smarthome.model.script.Scenario] - 5-newscene :i didn’t

strange it worked with simple quotes till now :slight_smile:

Merci