Number of options in comma separated string.

zulq
Member Posts: 204
Hi,
I would like to know how to get the number of substrings in a string with comma separated values. For example:
Thanks.
I would like to know how to get the number of substrings in a string with comma separated values. For example:
str := 'abcde,jhedk,kehhd,eieje,dkdkfj'This string has five strings with numbers 1-5. Thus if I want to get the last substring I just have to use selectstr(5,str). Now I want to be able to know the last number of the given string and thus loop through the end to get all substrings. Is there any way to get this number.
Thanks.
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
0
Answers
-
Anyone out there knows how to do this?Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?0
-
CountSubStrings(String : Text[250];Character : Text[1]) CharCount : Integer
// This function returns the count of elements in the string
// Character is the delimiter you are looking for ','
CharCount := 0; // local Var
CharPos := 0; // local Var
CountingString := ''; // local Var
CountingString := TrimString(String,Character); //Call to 2nd function below
CharPos := STRPOS(String,Character);
REPEAT
CountingString := COPYSTR(CountingString,CharPos+1);
CharCount := CharCount + 1;
CharPos := STRPOS(CountingString,Character);
UNTIL CharPos = 0;
EXIT(CharCount + 1);
TrimString(String : Text[250];Character : Text[1]) TrimmedString : Text[250]
//This removes the Character from the beginning and/or end of the string and returns the trimmed string
TrimmedString := String;
IF (STRPOS(String,Character) = 1) THEN
TrimmedString := COPYSTR(String,2);
IF (COPYSTR(String,STRLEN(String)) = Character) THEN
TrimmedString := COPYSTR(TrimmedString,1,STRLEN(TrimmedString)-1);0 -
Thanks SPost29.Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?0
-
You also might try this one.
Str := 'abcde,jhedk,kehhd,eieje,dkdkfj';
MESSAGE('%1',STRLEN(DELCHR(UPPERCASE(Str),'=','ABCDEFGHIJKLMNOPQRSTUVWXYZ')) + 1);
If your option string contains any other chars besides a-z you should append them to the pattern string.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