code: static String encodeURLString(String stringToEncode) {
          try {
              return java.net.URLEncoder.encode(stringToEncode, "UTF-8").replace("+", ENCODED_SPACE_CHARACTER);
          } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e); // can't happen
          }
      }
docs: Encode a string using URL encoding
  
  @param stringToEncode The string to URL encode