title: How to preserve white spaces in function arguments in Informix?
body: <p>I'm trying to create a version of InStr function for Informix 11.5. Here's the code:</p>
  
  <pre><code>CREATE FUNCTION MY_INSTR(txt VARCHAR(255), term VARCHAR(255))
      RETURNING VARCHAR(255);
    DEFINE i INTEGER;
    DEFINE len INTEGER;
    DEFINE lenterm INTEGER;
  
    LET i = 1;
    LET lenterm = LENGTH(term);
    LET len = LENGTH(txt) - lenterm;
  
    WHILE ( i &lt;= len ) LOOP
      IF SUBSTR( txt, i, lenterm ) = term THEN
        RETURN i;
      END IF
      LET i = i + 1;
    END LOOP
  
    RETURN 0;
  END FUNCTION;
  </code></pre>
  
  <p>I'll use this function to get the first name of a user in a column with the full name, like this:</p>
  
  <pre><code>SELECT SUBSTR(name, 1, MY_INSTR(name, " ")) AS firstname
    FROM users
  </code></pre>
  
  <p>I need to pass the value <code>" "</code> as the term, but when I do, <code>lenterm</code> equals 0.</p>
  
  <p>Is there a way to preserve white spaces when passing them to a function in Informix?</p>