How to remove the first or last space from a string
For example, I have a string str= ' this is a string ', there are spaces at the beginning and the end of this string, how can I remove it in Netlinx studio?
Thanks
Thanks
Comments
DEFINE_CONSTANT #IF_NOT_DEFINED HT HT = $09 #END_IF // Name : ==== Trim Left ==== // Purpose: Trim leading spaces from a string // Params : (1) IN/OUT - char inputdata[]/char formatteddata[] // Returns: Char array representing the input string with leading spaces removed // Notes : // define_function char[MAX_WIDTH_STRING] TrimLeft(char _cInputString[]) { stack_var integer _nResultStartPos _nResultStartPos = 1 while ( (_nResultStartPos <= length_array(_cInputString)) && ( (_cInputString[_nResultStartPos] = ' ') || (_cInputString[_nResultStartPos] = "HT") ) ) { _nResultStartPos++ } if(_nResultStartPos <= length_array(_cInputString)) return right_string(_cInputString, length_array(_cInputString) - _nResultStartPos + 1) else return '' } // Name : ==== Trim Right ==== // Purpose: Trim trailing spaces from a string // Params : (1) IN/OUT - char inputdata[]/char formatteddata[] // Returns: Char array representing the input string with leading spaces removed // Notes : // define_function char[MAX_WIDTH_STRING] TrimRight(char _cInputString[]) { stack_var integer _nResultStartPos _nResultStartPos = length_array(_cInputString) while ( (_nResultStartPos) && ( (_cInputString[_nResultStartPos] == ' ') || (_cInputString[_nResultStartPos] == "HT") ) ) { _nResultStartPos-- } if(_nResultStartPos) return left_string(_cInputString, _nResultStartPos) else return '' } // Name : ==== Trim ==== // Purpose: Trim leading and trailing spaces from a string // Params : (1) IN/OUT - char inputdata[]/char formatteddata[] // Returns: Char array representing the input string with leading and trailing spaces removed // Notes : // define_function char[MAX_WIDTH_STRING] Trim(char _cInputString[]) { stack_var char _cResultString[MAX_WIDTH_STRING] // Remove leading spaces from the string _cResultString = TrimLeft(_cInputString) // Remove trailing spaces from the string _cResultString = TrimRight(_cResultString) return _cResultString }Thanks Auser!
Will this command work? send_command TP,"'TEXT1,2,3,5-CD'"
I've just updated that code snippet to include a definition for the horizontal tab ASCII character which I had inadvertently omitted.
BMF can do this too (I think) but the ^TXT is a bit simpler.
So Send-command tp,"'^TXT-1&2&3&5,1&2,Test only'" will send text to button 1,2,3 and 5?
I would write it like this: I would use the . (dot) operator so 1 through 3 (1.3) and 5 (&5) and for states 0 equals states 1 & 2.
Question: Is there a way to remove the spaces before or after characters in a string?
Answer: TRIM_STRING
Question: Is there a way to search for characters in a string starting at the end?
Answer: FIND_STRING_REV
Question: Is there a way to replace specific characters, or remove specific characters, from a string?
Answer: REPLACE_STRING
Question: Is there a way to assign sub-strings separated by delimiters from a string to an array?
Answer: SPLIT_STRING
Question: Is there a way to count the number of times a pattern of characters occurs in a string?
Answer: COUNT_STRING
the variable text channels are random, they can be 1,3,5,7,10, how to send text to them?
I tested it with AXD-CV6 and a MVP5200i, send_command tp,"'^TXT-1&3&5&7&10,0,Text Only'" work in MVP5200i but not AXD-CV6, I checked the AXD-CV6 manual, could not find any multiple send text command.
MVP5200i = G4
^TXT is a G4 command
Aren't the differences between G3 and G4 panels distinguished well enough in the course of AMX training? If not - it should be.
I realized the difference between G3 and G4 panels, I just want to find a command can do both G3 and G4 panels.