get_buffer_char() not working?
fogled@mizzou
Posts: 549
I'm actually in Prog-II training class in Chicago today. Todd & crew send their love ;-)
While working on a string parsing exercise, the GET_BUFFER_CHAR() command was not returning any value. It would strip the first character off the CHAR array, but would not return a value.
Got String: gobbledygook
First Char:
Remaining String: obbledygook
Of course remove_string works as advertised, and using left_string with another character stripping command works too. Has anyone else run into this?
While working on a string parsing exercise, the GET_BUFFER_CHAR() command was not returning any value. It would strip the first character off the CHAR array, but would not return a value.
define_call 'parse_string' (char this_string[128]) { stack_var char first_char[2] send_string debug,"'Got String: ',this_string" first_char = get_buffer_char(this_string) send_string debug,"'First Char: ',first_char" send_string debug,"'Remaining String: ',this_string" }This code returns the following information on debug:
Got String: gobbledygook
First Char:
Remaining String: obbledygook
Of course remove_string works as advertised, and using left_string with another character stripping command works too. Has anyone else run into this?
0
Comments
I have had flaky results with Get_Buffer_Char. It is old-skool stuff left over from Axcess days. I tend not to use it much since there are so many other ways to do basically the same thing. Hence, I've never really investigated what's going on. I'd be curious to find out, however, since it is a handy way to strip of the first char of a string.
stack_var char first_char
I think you'll be okay. I can't quite explain why it behaves the way it does though.
The help says "Result is a CHAR or WIDECHAR value depending on the variable type of Array" which sort of implies this restriction.
"Why does the compiler allow it?" you may ask - another subtle compiler bug.
This looks like *yet another* example of the good old NS2 "Single character strings are sometimes flaky" problem, although back to front.
So
First_Char[1] = Get_Buffer_Char(This_String)
--D
[Everyone: off you go and do that now!]
Experiment also shows that AM93 is mistaken. Good idea, but specifying the index on the LHS does not apparently solve the problem and I have not experienced a similar solution elsewhere. I think.
Unfortunately this is simply wrong for a single dimension string.
May I urge contributors to this forum to experiment before they post?
Although this was refferring to the use of ATOI and get_buffer_char the same principle applies.
Sorry it took so long to get back to the forums on this. mpullin and AM93 are both right:
Defining a char without a length will allow it to receive the output of get_buffer_char. So will specifying which position (as above) the output goes into. It just doesn't work if you give the variable a length when you define it, and then don't specify a position to put the result into.
Although get_buffer_char() is one of the 'old' commands from the axess days, it still does something no other single string operator does: gets the first character without knowing what it is, and 'rolls' the buffer too. You have to know what character it is to get the same effect from remove_string().
I'm not sure I would recommend using get_buffer_char() if you don't really need that particular function, but that seems to be mostly the ongoing oddities of dealing with single character storage. As long as you know how to make it work - and AM93's solution above is the more 'recommended' way - you'll be OK.
// If you just need the char (preferred)
// If you need length
I do not have a master to test this on, but I think it would perform the same way as GET_BUFFER_CHAR except it would be more robust.