VTCSdude
25th May 2007, 16:41
Okay here comes another newb question.

Is there an equivilent to the C substr function in BaaN. If so what is the syntax?

bdittmar
25th May 2007, 16:49
Okay here comes another newb question.

Is there an equivilent to the C substr function in BaaN. If so what is the syntax?

Hello,

BaanERP Programmers Guide

pos(), rpos()
--------------------------------------------------------------------------------
Syntax
long pos( string source(.), string pattern(.) )
long rpos( string source(.), string pattern(.) )

Description
These return the start position of a specified substring (pattern) in a specified string (source). source and pattern can be either strings or string expressions.

pos() starts searching for the substring at the first position in the source string. rpos() starts searching at the last position in the source string. Both return the start position relative to the beginning of the source string.

Return values
The start position of the substring in the string. Or 0 if the substring is not found.

Context
Bshell functions.

Example
long posno
posno = pos("abcdabcd", "bcd") | posno contains 2
posno = rpos("abcdabcd", "bcd") | posno contains 6



Regards

Example:
----------------------------------------------------------------------------
If pos(tipcs021.dsca,"#")>0 Then |and pos(tipcs021.dsca,",")=0 T
hen
typ = tipcs021.dsca(1;pos(tipcs021.dsca,"#")- 1)
If pos(typ,",")>0 Then
option = typ(pos(typ,","))
typ = typ(1;pos(typ,",")- 1)

Endif
Else
If pos(tipcs021.dsca,",")>0 Then
typ = tipcs021.dsca(1;pos(tipcs021.dsca,",")- 1)
option = tipcs021.dsca(pos(tipcs021.dsca,","))
Else
--------------------------------------------------------------------------

george7a
28th May 2007, 16:49
Hi Bernd,

I think your last example is missing the end of the code..

- George

vahdani
28th May 2007, 16:57
Hi,

and there is always the ERP Programmers reference on our WIKI. As an example take a look at pos() rpos() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_string_operations_pos_rpos)

ciavaglia
30th May 2007, 21:46
Here is a way:
string2 = string1(start_position;length)

Example:
string1 = "abcdefg"
string2 = string1(3;2) |string2 now equals "cd'

bdittmar
31st May 2007, 11:48
Here is a way:
string2 = string1(start_position;length)

Example:
string1 = "abcdefg"
string2 = string1(3;2) |string2 now equals "cd'


Hello,

this is not like substring as VTCSdude asked.

It only gives a string from a position with a defined length.

I think the requirement is to search a defined pattern in a string where the patern can be on different positions in the string.

So you have to analize the string with "pos"

Regards

ciavaglia
31st May 2007, 19:20
bdittmar,

This is what I understand C substr to be:

string substr (size_type pos, size_type n);
Returns a substring of the current string, starting at position pos and of length n:

Therefore, what I wrote is correct.

VTCSdude, let me know if this is what you are looking for.

bdittmar
31st May 2007, 20:47
bdittmar,

This is what I understand C substr to be:

string substr (size_type pos, size_type n);
Returns a substring of the current string, starting at position pos and of length n:

Therefore, what I wrote is correct.

VTCSdude, let me know if this is what you are looking for.

Hello ciavaglia,

what you wrote is correct, but it alwas give the string from position, length.

Let me explain :

you have 4 strings

newschool
school
oldschool
private school

If your's is string(4,6) the result will be :

school
ool
school
vate s

with pos function it is always "school"

OK let VTCSdude explain his requirements.

Regards

ciavaglia
31st May 2007, 20:58
bdittmar,

Your example of pos() and rpos() does the C strstr function, not substr.