Need help in parsing this string

zohaibu95@hotmail.com
Member Posts: 223
Hi guys,
I need help in parsing the below mentioned string.
What i want is, i first want to split it on the basis of ';' and after getting individual token i want to split it on the basis of ',' . There can be more in the string separate by ';' .
Any one recommend how can i do this? There is no SPLIT function as in c#.
Plzz help. Thanks
I need help in parsing the below mentioned string.
RP50001,201232,London;RP50002,201392,USAetc
What i want is, i first want to split it on the basis of ';' and after getting individual token i want to split it on the basis of ',' . There can be more in the string separate by ';' .
Any one recommend how can i do this? There is no SPLIT function as in c#.
Plzz help. Thanks
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
0
Best Answers
-
In C/AL you can use something like this:
OnRun() SemiColon := ';'; Comma := ','; String := 'RP50001,201232,London;RP50002,201392,USA'; String2 := Split(String, SemiColon, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String2); String := COPYSTR(String, Pos+1); String3 := Split(String2, Comma, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String3); String2 := COPYSTR(String2, Pos+1); String3 := Split(String2, Comma, Pos); END; IF String3 <> '' THEN MESSAGE(String3); String2 := Split(COPYSTR(String, Pos+1), SemiColon, Pos); END; IF String2 <> '' THEN BEGIN String3 := Split(String2, Comma, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String3); String2 := COPYSTR(String2, Pos+1); String3 := Split(String2, Comma, Pos); END; IF String3 <> '' THEN MESSAGE(String3); END; LOCAL Split(String : Text;Sep : Text[1];VAR Pos : Integer) : Text Pos := STRPOS(String, Sep); IF Pos > 0 THEN EXIT(COPYSTR(String, 1, Pos-1)) ELSE EXIT(String);
Every variable is Text except Pos that is Integer.
Regards.5 -
In this case maybe you didn't check the option Var in the Pos parameter inside the Split function.
5
Answers
-
You can use .NET
Take a look at this, i havent added a example for split, but if you know C#, then you should feel right at home.
https://juhl.blog/2017/04/24/text-manipulation-using-net/Follow me on my blog juhl.blog0 -
@Juhl , Thanks for the quick reply juhl. Actually i want to do it without DotNet variable so i am looking out for the ways through which we can parse this string (by looping and conditions).
Looking forward.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.0 -
Hi,
As suggested, .NET is your friend. Here is an example:
SemiColon := ';';
Comma := ',';
String := 'RP50001,201232,London;RP50002,201392,USA';
FOREACH SemiColonStrings IN String.Split(SemiColon.ToCharArray) DO BEGIN
MESSAGE('%1', SemiColonStrings);
FOREACH CommaStrings IN SemiColonStrings.Split(Comma.ToCharArray) DO BEGIN
MESSAGE('%1', CommaStrings);
END;
END;
where variables are:
0 -
Why not use the power of .NET ???
It's translated into C# anyway
https://juhl.blog/2017/04/24/cal-vs-c-i-dynamics-nav/Follow me on my blog juhl.blog0 -
In C/AL you can use something like this:
OnRun() SemiColon := ';'; Comma := ','; String := 'RP50001,201232,London;RP50002,201392,USA'; String2 := Split(String, SemiColon, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String2); String := COPYSTR(String, Pos+1); String3 := Split(String2, Comma, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String3); String2 := COPYSTR(String2, Pos+1); String3 := Split(String2, Comma, Pos); END; IF String3 <> '' THEN MESSAGE(String3); String2 := Split(COPYSTR(String, Pos+1), SemiColon, Pos); END; IF String2 <> '' THEN BEGIN String3 := Split(String2, Comma, Pos); WHILE Pos > 0 DO BEGIN MESSAGE(String3); String2 := COPYSTR(String2, Pos+1); String3 := Split(String2, Comma, Pos); END; IF String3 <> '' THEN MESSAGE(String3); END; LOCAL Split(String : Text;Sep : Text[1];VAR Pos : Integer) : Text Pos := STRPOS(String, Sep); IF Pos > 0 THEN EXIT(COPYSTR(String, 1, Pos-1)) ELSE EXIT(String);
Every variable is Text except Pos that is Integer.
Regards.5 -
You can change semicolon to comma (if possible) and then split comma delimited string - for example by using SELECTSTR function.0
-
Thanks @ftornero . But there is issue in your code the pos is always remains 0 as a result it is causing issue.and only display RP50001 nothing elseBest Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.0 -
In this case maybe you didn't check the option Var in the Pos parameter inside the Split function.
5 -
Thanks @ftornero . I already did thatBest Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.0 -
I am using this function since 2001 or so. Always served me well:
Entry(PintEntry : Integer;PtexEntries : Text[1024];PtexSeperator : Text[1]) PtexReturnValue : Text[1024]
// Entry
// gives anentry of a list base on an integer
// (like Navision SELECTSTR, but without bugs)
// PARAMETERS :
// PintEntry : which element must be returned
// IF (PintElement <= 0) OR (PintElement > NumEntries(PtexEntries,PtexSeperator))
// THEN '' is returned
// PtexEntries : list
// PtexSeperator : charakter used as seperator
// if = '' then ',' is used
// PtexReturnValue : selected element
PtexReturnValue := '';
LintLength := STRLEN(PtexEntries);
IF (LintLength = 0) OR
(PintEntry <= 0) THEN
EXIT('');
IF PtexSeperator = '' THEN
PtexSeperator := ',';
Lint := 0;
WHILE Lint < LintLength DO BEGIN
Lint := Lint + 1;
IF COPYSTR(PtexEntries,Lint,1) = PtexSeperator THEN
PintEntry := PintEntry - 1
ELSE IF PintEntry = 1 THEN
PtexReturnValue := PtexReturnValue + COPYSTR(PtexEntries,Lint,1);
END;
EXIT(PtexReturnValue);Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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