Use char arrays instead strings

I have made sketch with arduino uno and esp8266 in which i send measures of HC-SR04 to a website. I want to convert the code so I can use char arrays instead strings. How can I do this? Can someone help me with a few lines of code? My code is:

#include <SoftwareSerial.h>
SoftwareSerial espSerial =  SoftwareSerial(2,3);  

//Wifi network SSID password
String ssid="ffffff";
String password ="*******";

boolean DEBUG=true;

int echoPin = 12; 
int trigPin = 13; 

long duration, distance; 
int alarm;

String alarms;

String data;
String server = ""; // Send data to this site

String uri = "/add2.php";

int error = 0;
int cancel = 0;

void showResponse(int waitTime){
    long t=millis();
    char c;
    while (t+waitTime>millis()){
      if (espSerial.available()){;
        if (DEBUG) Serial.print(c);

boolean websiteWrite(long value1, int value2){ 
  if (value2 == 0){
    alarms = "OFF";
    alarms = "ON";
  data = "distance=" + String(value1) + "&alarm=" + alarms;
  espSerial.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
  if( espSerial.find("OK")) {
  Serial.println("TCP connection ready"); cancel = 0;
    cancel = cancel + 1;  Serial.println("cancel="); Serial.println(cancel);
  String postRequest =
  "POST " + uri + " HTTP/1.0\r\n" +
  "Host: " + server + "\r\n" +
  "Accept: *" + "/" + "*\r\n" +
  "Content-Length: " + data.length() + "\r\n" +
  "Content-Type: application/x-www-form-urlencoded\r\n" +
  "\r\n" + data;
  String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
  espSerial.println(postRequest.length() );
  if(espSerial.find(">")) { Serial.println("Sending.."); espSerial.print(postRequest);
  if( espSerial.find("SEND OK")) { Serial.println("Packet sent");
  while (espSerial.available()) {
  String tmpResp = espSerial.readString();
  // close the connection
    error = 0;
    error = error + 1;
  if(cancel >=15 || error >= 15){software_Reset() ;}

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);


  if (DEBUG)  Serial.println("Setup completed");  

void loop() {

  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
  if (distance<=8){
      if (isnan(distance)) {
        if (DEBUG) Serial.println("Failed of calculation the distance");
      else {
          if (DEBUG)  Serial.println("Distance="+String(distance)+" cm");
           websiteWrite(distance,alarm);                                      // Write values to website
  //Needs 60 sec delay between updates    

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
asm volatile ("  jmp 0");  

An example of building an HTML string

void handleRoot()
  snprintf(HTMLbuffer, HTMLbufferSize, "<!DOCTYPE html>\
.colourSquare {width: 300px; height: 300px; font-size: 80px; color: WHITE; font-weight:bold; display: inline-block;}\
<form action=\"/redLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:RED;\" value=\"%s\"></form>\
<form action=\"/greenLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:GREEN;\" value=\"%s\"></form>\
<form action=\"/blueLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:BLUE;\" value=\"%s\"></form>\
</html>", redText, greenText, blueText);
  server.send(200, "text/html", HTMLbuffer );
  Serial.print("leaving handleRoot\t");

This example builds the HTML and inserts the values for red, green and blue text previously set in another part of the program.

The primary difference is that char arrays that are treated as strings by appending a null character, '\0', at the end of the characters that comprise the array. The null character serves as a sentinel to mark the end of the string. The string name serves as the start of the string. For example:

   char passWord[10];

   strcpy(passWord, "secret");

Note that because passWord[] is defined as having 10 elements, the max length of passWord[] is 9 characters, because there must be room for the null. Also note in the string copy function, the first argument is passWord with no brackets. This illustrates that passWord by itself (i.e., no brackets) is viewed by the compiler as &password[0], or the starting memory address of the string array of chars. Most of the string processing functions are of the form shown here:

_ str*(destinationString, sourceString);_

Unlike the String class (note the uppercase 'S'), manipulation of string data (note lower case 's') is done via library functions rather than by operators. You can find a summary of the mem*() and str*() string processing functions here. As a general rule, the mem*() functions have less error checking code associated with them (e.g., overlaps, lengths, etc.) so they are often marginally faster than their str*() counterparts.

The evils of Strings page tells why we don't like to use Strings and how to use some string functions in their place.