How do I strip leading spaces from a number?
I have a floating point value coming in from my device. When there are no leading spaces, everything is fine. However, if there is some spaces before the number, OmniServer can't read it. How can I set up OmniServer to strip off the leading spaces?
There are two ways to do this:
- If the data is a fixed length, then you can place a Length specifier on the item in the message. For example, suppose there are ten characters in the data field and your data item is called "Float". The sequence in the message will look like this:
{Float:10}. This tells OmniServer to always expect ten characters for the float. Any leading spaces will be stripped out. - If the data is not a fixed length, you will need to use the "Ignore Leading Spaces on Numerics" specifier on the item in the message. For example, suppose you have an item called "Float" that is followed by a carriage return. The sequence in the message will look like this:
{Float:Q}{$CR}. This tells OmniServer to expect any number of characters up to a Carriage Return, strip out any leading spaces, and return the resulting number to the client.