#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Options

# how to do string split in NAV

Member Posts: 8
edited 2012-05-19
Does anyone know how to do string split in NAV. I've a string like 'ABC/11-12/001;ABC/11-12/002;ABCDE/11-12/0001'
and i want to split it like string1:=ABC/11-12/001. string2:=ABCDE/11-12/0001.

• Options
Member Posts: 71
Hi Savrav,

MyString := 'ABC/11-12/001;ABC/11-12/002;ABCDE/11-12/0001';
TempString := CONVERTSTR(MyString,';',',');

String1 := SELECTSTR(1,TempString);
String2 := SELECTSTR(2,TempString);
String3 := SELECTSTR(3,TempString);

Message('%1',String1); // Gives ABC/11-12/001
Message('%1',String1); // Gives ABC/11-12/002
Message('%1',String1); // Gives ABCDE/11-12/0001

Hope This Solve Your Problem. . .

Thanks & Regards,
Purvesh Maisuria.
• Options
Member Posts: 71
Hi Sourav,

Changes in Bellowed Code.

Message('%1',String1); // Gives ABC/11-12/001
Message('%1',String2); // Gives ABC/11-12/002
Message('%1',String3); // Gives ABCDE/11-12/0001

Technique 2 :
2.Way :

Note : "Pos" is a local integer variable

Token(VAR Text : Text[1024];Separator : Text[1]) Token : Text[1024]

Pos := STRPOS(Text,Separator);
IF Pos > 0 THEN BEGIN
Token := COPYSTR(Text,1,Pos-1);
IF Pos+1 <= STRLEN(Text) THEN
Text := COPYSTR(Text,Pos+1)
ELSE
Text := '';
END ELSE BEGIN
Token := Text;
Text := '';
END;

Then call the code like this:

string := 'ABC-111-124';

Part1 := Token(string,'-'); // Returns 'ABC' and changes string to '111-124'
Part2 := Token(string,'-'); // Returns '111' and changes string to '124'
Part3 := Token(string,'-'); // Returns '124' and changes string to ''