Strings and things

aztecconsulting
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?
0
Comments
-
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.0 -
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"?0 -
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.0 -
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 railgun0 -
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.0
-
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 railgun0 -
That's how I'll do it then...I'm just used to the MID$ of Visual Basic...Thanks for the input!0
-
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 railgun0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions