API.Ai how do you get string between character?

I’m not game programmer. I need to make a program communicate back to you.
How do you get string between?

Type: “hello”
Response: “Howdy”

But I’m getting this results… I don’t need them.
Result: {“id”:“fd7436a6-a757-42e8-b98a-cff28b21e6d4”,“timestamp”:“2017-04-25T23:18:00Z”,“result”:{“action”:“smalltalk.greetings”,“parameters”:{“simplified”:“hello”},“metadata”:{},“resolvedQuery”:“hi”,“fulfillment”:{“speech”:“Howdy.”},“source”:“domains”},“status”:{“code”:200,“errorType”:“success”},“IsError”:false}
UnityEngine.Debug:Log(Object)
ApiAiModule:SendText() (at Assets/Examples/ApiAiModule.cs:175)
UnityEngine.EventSystems.EventSystem:Update()

Here’s the code:

using UnityEngine;
using UnityEngine.UI;
using System;
using System.IO;
using System.Collections;
using System.Reflection;
using ApiAiSDK;
using ApiAiSDK.Model;
using ApiAiSDK.Unity;
using Newtonsoft.Json;
using System.Net;
using System.Collections.Generic;

public class ApiAiModule : MonoBehaviour
{

    public Text answerTextField;
    public Text inputTextField;
    private ApiAiUnity apiAiUnity;
    private AudioSource aud;
    public AudioClip listeningSound;

    private readonly JsonSerializerSettings jsonSettings = new JsonSerializerSettings
    {
        NullValueHandling = NullValueHandling.Ignore,
    };

    private readonly Queue<Action> ExecuteOnMainThread = new Queue<Action>();

    // Use this for initialization
    IEnumerator Start()
    {
        // check access to the Microphone
        yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
        if (!Application.HasUserAuthorization(UserAuthorization.Microphone))
        {
            throw new NotSupportedException("Microphone using not authorized");
        }

        ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) =>
        {
            return true;
        };
           
        const string ACCESS_TOKEN = "3485a96fb27744db83e78b8c4bc9e7b7";

        var config = new AIConfiguration(ACCESS_TOKEN, SupportedLanguage.English);

        apiAiUnity = new ApiAiUnity();
        apiAiUnity.Initialize(config);

        apiAiUnity.OnError += HandleOnError;
        apiAiUnity.OnResult += HandleOnResult;
    }

    void HandleOnResult(object sender, AIResponseEventArgs e)
    {
        RunInMainThread(() => {
            var aiResponse = e.Response;
            if (aiResponse != null)
            {
                Debug.Log(aiResponse.Result.ResolvedQuery);
                var outText = JsonConvert.SerializeObject(aiResponse, jsonSettings);
               
                Debug.Log(outText);
               
                answerTextField.text = outText;
               
            } else
            {
                Debug.LogError("Response is null");
            }
        });
    }
   
    void HandleOnError(object sender, AIErrorEventArgs e)
    {
        RunInMainThread(() => {
            Debug.LogException(e.Exception);
            Debug.Log(e.ToString());
            answerTextField.text = e.Exception.Message;
        });
    }
   
    // Update is called once per frame
    void Update()
    {
        if (apiAiUnity != null)
        {
            apiAiUnity.Update();
        }

        // dispatch stuff on main thread
        while (ExecuteOnMainThread.Count > 0)
        {
            ExecuteOnMainThread.Dequeue().Invoke();
        }
    }

    private void RunInMainThread(Action action)
    {
        ExecuteOnMainThread.Enqueue(action);
    }

    public void PluginInit()
    {
       
    }
   
    public void StartListening()
    {
        Debug.Log("StartListening");
           
        if (answerTextField != null)
        {
            answerTextField.text = "Listening...";
        }
           
        aud = GetComponent<AudioSource>();
        apiAiUnity.StartListening(aud);

    }
   
    public void StopListening()
    {
        try
        {
            Debug.Log("StopListening");

            if (answerTextField != null)
            {
                answerTextField.text = "";
            }
           
            apiAiUnity.StopListening();
        } catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
   
    public void SendText()
    {
        var text = inputTextField.text;

        Debug.Log(text);

        AIResponse response = apiAiUnity.TextRequest(text);

        if (response != null)
        {
            Debug.Log("Resolved query: " + response.Result.ResolvedQuery);
            var outText = JsonConvert.SerializeObject(response, jsonSettings);

            Debug.Log("Result: " + outText);

            answerTextField.text = outText;
        } else
        {
            Debug.LogError("Response is null");
        }

    }

    public void StartNativeRecognition()
    {
        try
        {
            apiAiUnity.StartNativeRecognition();
        } catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
}

In inspector assign answerTextField. For that, use Unity UI to create Text Field and drag it to answerTextField in ApiAiModule script that is on game object in your scene.

And those Results, they are not something for the user, it’s for developer. User is interacting with Game View only. You can Delete this:

  Debug.Log("Resolved query: " + response.Result.ResolvedQuery);
            var outText = JsonConvert.SerializeObject(response, jsonSettings);
            Debug.Log("Result: " + outText);

If you don’t want to see those Results.

Not sure if I answered your question fully.

It’s print this:
Result: {“id”:“fd7436a6-a757-42e8-b98a-cff28b21e6d4”,“timestamp”:“2017-04-25T23:18:00Z”,“result”:{“action”:“smalltalk.greetings”,“parameters”:{“simplified”:“hello”},“metadata”:{},“resolvedQuery”:“hi”,“fulfillment”:{“speech”:“Howdy.”},“source”:“domains”},“status”:{“code”:200,“errorType”:“success”},“IsError”:false}
UnityEngine.Debug:Log(Object)
ApiAiModule:SendText() (at Assets/Examples/ApiAiModule.cs:175)
UnityEngine.EventSystems.EventSystem:Update()

I don’t need those. I’m looking for string between “speech” – “}” . I tried this code. It doesn’t work.

            int startIndex = outText.IndexOf("speech") + "speech".Length;
            int endIndex = outText.IndexOf("}");
            string newString = outText.Substring(startIndex, endIndex - startIndex);


            Debug.Log ("Result: " + newString);

Debug says…
ArgumentOutOfRangeException: Cannot be negative.
Parameter name: length