Initalizing a string to certain characters

aztecconsulting
Member Posts: 55
What is the C/SIDE equalivent for the VB6 String() function?
This function takes 2 arguments:
Function String(Number As Long, Character) As String
The return value is a string of characters specified by the Character argument, repeated Number times.
String(4, "O") returns "OOOO".
String(4, 65) returns "AAAA".
This function takes 2 arguments:
Function String(Number As Long, Character) As String
The return value is a string of characters specified by the Character argument, repeated Number times.
String(4, "O") returns "OOOO".
String(4, 65) returns "AAAA".
0
Comments
-
-
Actually I can't which is why I am posting the request here. I'm still learning C/SIDE without any training and only limited documentation. I am hoping the new user group will improve the situation but for now I have to rely on the kindness of strangers when I get stuck with an issue I can resovle myself.0
-
You could use the PADSTR function. You must have predefined your text variable to whatever maximum length you want to allow. Example
xtest text 30
The command
xtest := PADSTR('',5,'Q');
will give you a string of 'QQQQQ'
The command
xtest := padstr(xtest,maxstrlen(xtest),'m');
will pad out the existing contents of xtest with m's. If it were applied right after the previous command, the result would be
'QQQQQmmmmmmmmmmmmmmmmmmmmmmmmm'
If that were followed by the command
xtest := PADSTR('',7,'P');
the result would be 'PPPPPPP'Dave Studebaker
Co-Founder Liberty Grove Software
Author: Programming Microsoft Dynamics NAV (V5.0), 2009, 20130 -
Thanks! That resolved it and is what I was looking for! I really wish some VB developer would write a guide to C/SIDE for Visual Basic Developers!0
-
Well you could start a new codeunit for 'useful functions', let's give it number 50000. Inside that coduenit you open the globals (View/Globals) on the functions tab. Enter a new line and call it RepeatString. Then you click on the Locals button and you enter two parameters. One Integer called MyNumber and one text variable called MyString (set it to 1024 length). On the return value, you set the type to text, and call it ReturnString.
Then in the trigger, you enter a local integer variable called Index, and you write the following code:ReturnString := ''; FOR Index := 1 TO MyNumber DO BEGIN ReturnString := ReturnString + MyString; END;
Of course you should also program some safeguards in it to check for maximum length and stuff like that, to prevent overruns.
Now you can call this function from anywhere in Navision. All you need to do is declare the codeunit in your variables and call the RepeatString function with the values you specify.0 -
Or you could use the PADSTR function :oops: forgot all about that one.0
-
Yeah, I'm having to use padstr for some of the formatting already. One issue that just came us is that padstr pads left-justifed, what if I need right-justified? I mean I have a field with a value of 1000 but it's 6 bytes and the vendor expects 001000 using pad would return 100000 so that's not going to work.0
-
You can use this function:
PadStrLeft(String : Text[250];Length : Integer;FillCharacter : Text[1]) NewString : Text[250] WHILE STRLEN(String) < Length DO String := FillCharacter + NewString; NewString := String;
Hey, Daniel, it's from the same archives as the one from yesterday.Nelson Alberto0 -
aztecconsulting wrote:I am hoping the new user group will improve the situationNelson Alberto0
-
Hi,
this is my version of PADSTR left.
I found this thread after I finished my code.
My code doesn't have no WHILE statement.
And it also truncate the string if ln_len is smaller then lc_str (same as PADSTR)
Phil :P
>>>>>>>>>>>>
PADL(lc_str : Text[255];ln_Len : Integer;lc_padChar : Text[1]) : Text[255]
IF ln_Len > 255 THEN
ERROR('Max length is 255');
lc_str2 := COPYSTR(lc_str,1,ln_Len);
lc_str1 := PADSTR('',ln_Len-STRLEN(lc_str2),lc_padChar);
EXIT(lc_str1 + lc_str2);0
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