copystr in line 2

hi,how to copy str in line 2??

NewStr := COPYSTR(Str, Position, Length);

for example

HDR test

SHR test – line 2

how to know SHR’s posistion and length

you may try to use STRPOS (String) ; Use this function to search for a substring inside a string.

Position := STRPOS(String, SubString)

it’s available in help.

I still don’t get it…

it still consumed 2 records

JFFile.TEXTMODE(TRUE);
JFFile.WRITEMODE(FALSE);
JFFile.OPEN(‘C:\Test2.txt’);

REPEAT
JFFile.READ(vstring);

Pos1 := STRPOS(vstring,‘SHR’);
IF Pos1 = 0 THEN
vstring1 := COPYSTR(vstring,1,250);

Pos2 := STRPOS(vstring,‘HDR’);
IF Pos2 = 1 THEN
vstring2 := COPYSTR(vstring,1,250);

systemheadertag := COPYSTR(vstring1,1,3);
partnerid := COPYSTR(vstring1,4,9);
EdiType := COPYSTR(vstring2,4,6);
DF.FINDLAST;
DF.“Entry No.” := DF.“Entry No.” + 1;
DF.“1-System Header Tag” := systemheadertag;
DF.“1-Partner ID” := partnerid;
DF.VALIDATE(“2-Header Tag”,‘TES’);
DF.VALIDATE(“2-EDI Message Type”,EdiType);
DF.INSERT(TRUE);

UNTIL
JFFile.POS = JFFile.LEN;

i can’t use text

but how I separate from bigtext to text1, text2,text3

thanks

in getting part of text from bigtext, you can use: bigtextVart.GETSUBTEXT(TheTextVar, StartPos) -or- bigtextVart.GETSUBTEXT(TheTextVar, StartPos, length)

bigtextVart.GETSUBTEXT(TheTextVar, StartPos, length)

this is replacement for → vstring1 := COPYSTR(vstring,1,250);

but how to do the strpos?

something like
Pos1 := STRPOS(vstring,‘SSS’);

the problem is

not every data filled

for example if empty

how to catch that value?

if empty than fill it with 0

LineNumberText := COPYSTR(vstring3,9,3);
IF vstring3 = ‘@’ THEN
BEGIN
IF LineNumberText=’ ’ THEN
EVALUATE(LineNumber,‘0’)
END
ELSE
EVALUATE(LineNumber,LineNumberText);

→ failed

as for strpos, you need interger of pos, the text-var, and sub-text that you want to search.
ex. text-var is ‘I want to know how to do this?’ ; sub-text is ‘want’
when you do: pos := strpos(text-var,sub-text)
the result is: pos = 3

capturing empty character in sting can be a challenge. it can be one or some char(s) of white space, or null, or one char with blank value. if i’m not wrong, null or one blank is ‘’ (double quote, without space sign in between), but one or several white space characters is NOT considered as ‘’.

user can write anything to ‘vstring3’. but on ‘linenumbertext’ you need to check if it contains null/blank and three white space? am i correct? is there any other possibility that make you can not process the data?

assuming those 2 possibilities only, may be you can try to change as,

var vstring3 - text - 100
var linenumbertext - text - 3

if vstring3 = ‘’ then EVALUATE(LineNumber,‘0’)
else begin
LineNumberText := COPYSTR(vstring3,9,3);
if linenumbertext = ’ ’ then EVALUATE(LineNumber,‘0’) // (’ ‘) is 2 apostrophes and 3 white spaces in between
{you don’t need to worry about linenumbertext=’’ anymore, because you have check in line 1}
else EVALUATE(LineNumber,LineNumberText);

perhaps your next challenge is when vstring3 contain 1 or 2 white spaces and letter/number, example 20 or 19 or 1__ or __1 ; consider ‘_’ as space. for that, you may need to incorporate DELCHR(linenumbertext,’=’);

example: linenumbertext := DELCHR(linenumbertext,’=’);
read help for more detail about DELCHR command.

already solved

it seems just like this

if STRLEN(linenumbertext) = 0 then

thanks a lot Joe marselo

Terima kasih :slight_smile:

well, good to hear that.

do you test what happen if . . .
" when linenumbertext contain 1 or 2 white spaces and letter/number, example 20 or 19 or 1__ or __1 ; consider ‘_’ as space "

just curious, and sama-sama man!

already…

if ’ 2’

it means 2

  • Hatur nuhun joe :slight_smile: