static void TextBuffer(Args _args)
{
TextBuffer buffer;
str source;
;
source = "I am first,I am second,I am third";
buffer = new TextBuffer();
buffer.setText(source);
while (buffer.nextToken(0, ','))
{
info (buffer.token());
}
}
This blog is for Dynamics AX (AXAPTA) Developers,this will help you for your development issues. This site contains some Microsoft Dynamics AX X++ Codes for use in your day to day use.
Subscribe to:
Post Comments (Atom)
Ledger Voucher creation Framework and x++ code to create ledger voucher
Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...
-
{ "Message" : "Please verify that the user is valid and set up correctly." } Sol: System Administration > Se...
-
Please click here to access Custom Workflow step by step process:
-
FormRun formRun = sender.formRun(); Object inventTrans_ds = formRun.dataSource(formDataSourceStr(InventMarking,InventTransO...
You will run into problems if the seperator causes empty results.
ReplyDeleteExample: using source = ",I am second,I am third,,I am fifth,,";
7 fields, as there are 6 ',' seperators.
static void TextBuffer2(Args _args)
{
TextBuffer buffer;
str source;
int startPos;
int foundIdx = 0;
;
source = ",I am second,I am third,,I am fifth,,";
buffer = new TextBuffer();
buffer.setText(source);
foundIdx = 0;
while (buffer.nextToken(0, ','))
{
foundIdx++;
info (strfmt('%1 - %2', foundIdx, buffer.token()));
}
// old-school
buffer = new TextBuffer();
buffer.setText(source);
startPos = 1;
foundIdx = 0;
while (buffer.find(',', startPos))
{
foundIdx++;
info(strfmt('%1 - %2', foundIdx, buffer.subStr(startPos, buffer.matchPos()-startPos)));
startPos = buffer.matchPos() + buffer.matchLen();
}
if (startPos <= buffer.size()+1)
{
foundIdx++;
info(strfmt('%1.- %2', foundIdx, buffer.subStr(startPos, buffer.size()-startPos+1)));
}
}
Output:
1 - I am second
2 - I am third
3 - I am fifth
1 -
2 - I am second
3 - I am third
4 -
5 - I am fifth
6 -
7.-
Oldschool = bad, but correct.