How do I split string at | and result to variables?

I am new to MIT and have tried to split a string.
How to split string at | and result to variables ?

The ESP32 code

if(currentMillis - previousMillis_BLE1 > interval_BLE1) {
float TemperatureBLE1 = random(10,60000)/1000.0; // 3 decimals
float HumidityBLE1 = random(5,99000)/1000.0; // 3 decimals

String temperatureBLE1 = String(TemperatureBLE1,2);
String humidityBLE1 = String(HumidityBLE1,2);
String tem_hum_BLE1 = temperatureBLE1 + "|" + humidityBLE1 + "|" + humidityBLE1;

  std::string value = pCharacteristic->getValue();
  pCharacteristic->setValue(tem_hum_BLE1.c_str()); // Notify.

Use the split at block in the text palette


splits by the delimiter to a list which you can then apply to variables


Am I heading in the right direction?

How to read the values from the list ?

You should use the replacement blocks and join the lbl_receiveBLE1.Text before you split. The way you have it is converting the list back into a string.

1 Like

Dear TIMA12,
Can you make a example ?

Please provide some output that you are trying to parse, as text here.

1 Like

The string from te ESP32 = (49.44|71.03|22.56)

What I want to achieve;
lbl_1_1 gets 49.44
lbl_1_2 gets 71.03
lbl_1_3 gets 22.56

Create a local list variable, and assign it to the split value. Set lbl_1_1's text to the 1st index of the list (use the get from list block), lbl_1_2's text to the 2nd index, and lbl_1_3's text to the 3rd index.

Like so ?


Yes, it works.
Thanks for the effort.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.