Options

Strings and things

aztecconsultingaztecconsulting Member Posts: 55
For this exercise I have a variable typed as text with a length of 5. I set the value to all spaces using PADSTR('',5,' '). Now I want to change the second and third bytes to 5 so the string is " 55 " when complete. COPYSTR doesn't seem to work because it make a smaller substring from a larger string and not inserting the substring into the larger one. INSSTR also won't work because the string is fully initalized and the inserted text will push the variable over the five-byte boundary. Any ideas?

Comments

  • Options
    jhoekjhoek Member Posts: 216
    Since strings in C/SIDE can be addressed as if they were arrays of characters, you could try
    MyString[2] := '5';
    MyString[3] := '5';
    
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • Options
    aztecconsultingaztecconsulting Member Posts: 55
    That will help for single values but how can I put the contents of another variable like a zero-padded Store.Number into four bytes starting at position 2?

    How can I make " " equal " 0001"?
  • Options
    jhoekjhoek Member Posts: 216
    Good point. Sounds like one of these problems that are much easier to solve if you understand the situation behind it. Can you briefly explain why you need this, i.e. which practical challenge are you facing?
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • Options
    DakkonDakkon Member Posts: 192
    Unfortunately Navision has no good methods for doing string replacements. You pretty much have to do a complex cut/copy operation (concatenating substrings and such).
    I ended up just writing a dll in visual basic and making use of the cstringbuilder class that's been floating around forever. This way I just copy my string into my superstring class (or whatever you want to call it) and use it's methods for manipulation, and then copy the result back into my navision string.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • Options
    aztecconsultingaztecconsulting Member Posts: 55
    We are required to provide a feed of data where several fields may or may not be initialized. Each record in the output is 500 bytes and each byte should be a space or data from various tables. Only the last byte in the variable can be a null to signify the end of the line. I then have a table that shows what variables are to be put into this 500 line: Store Number is bytes 15-25 and Mall Name is 26-55 for example. I have thought if just using PADSTR to build each sub-string and then try a concatenate it but I'm not really sure how to do that either.
  • Options
    DakkonDakkon Member Posts: 192
    That's exactly what I would recommend in that case. Just start with your first field value and pad it out to the proper length, then move to the next and concatenate it's value to your first string, and so on until you reach the end.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • Options
    aztecconsultingaztecconsulting Member Posts: 55
    That's how I'll do it then...I'm just used to the MID$ of Visual Basic...Thanks for the input!
  • Options
    DakkonDakkon Member Posts: 192
    Here's a very simple hard coded example. I would personally recommend a table setup to specify all your fields, their lengths, and where they come from so that you can easily change the configuration without modifying code. That said here's a generic example. Assume we have a text variable 'tmp' for this example.
    tmp := '';
    tmp += PADSTR(Field1,Field1Length);
    tmp += PADSTR(Field2,Field2Length);
    etc ...
    
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
Sign In or Register to comment.