如何读取已使用“”转换为字符串的多值枚举之间的新行
How to read the new line between multi-valued enumerate that has been turned into a string using ""
我工作的模块中有一个枚举类型的多值属性。
外观如下:
// as it appears in the attribute column
val1
vals-2
vals3
// below is what is written in my script to turn the contents this attribute
// into a string (for this particular object)
string ovp = o."AttribName" // I have assigned it to a string in this manner
如果我打印字符串,它会以列格式打印出来,就像它出现在属性列中一样。新行是如何在此字符串中定义的?
我想使用新的行定义将每个枚举值放入一个字符串数组(string arr[size], 为了清楚起见,因为我可能没有使用正确的条款)。
我确信有办法,但我使用 DXL 才两周,我不知道该怎么做,或者如果有另一种方法可能更容易。
我已经尽可能多地使用我知道的关键字进行搜索。
在此先感谢您的帮助或指导。与此同时,我会继续尝试,看看我能想出什么。我假设如果我找到答案,我可以用它更新这个问题。
因此,可能有更好的方法来执行此操作,即查询属性定义,然后使用 'isMember' 函数 - 但这种方法将 return 一个您请求的字符串数组。
Object o = current
string s = o."Test Enum" ""
int x = 0
int y = 0
int size = 0
if ( s != "" ) {
size++
}
for ( x = 0 ; x < length ( s ) ; x++ ) {
if ( s [ x ] == '\n' ) {
size++
}
}
string arr[size]
size = 0
for ( x = 0 ; x < length ( s ) ; x++ ) {
if ( s [ x ] == '\n' ) {
arr[ size ] = s [ y : x - 1 ]
y = x + 1
size++
}
}
arr[ size ] = s [ y : ]
注意 - 这首先检查数组的大小,然后定义它。多个选定的属性以“\n”作为分隔符,但最后一个条目没有。
我发现一种适用于字母的方法是使用正则表达式。首先,我还想指出,我预先声明我的字符串数组的大小为 10,我可能可以将其减少到 5,因为值集似乎永远不会超过 4。这不是重点,这就是我发现对我的信件有用的东西。
string ovs = o.vs "", ovp = o.vp "", tempstr = ""
Regexp alphabet = regexp"[a-zA-Z]"
int pp, i = 0
for (pp = 0; pp <= length(ovs); pp++) {
if(alphabet ovs[pp]"")
tempstr = tempstr "" ovs[pp] ""
else {
vsstrarr[i] = tempstr "";
i++; tempstr = ""
}
}
这确实有效,但我不知道是否需要多个 Regexp 变量来捕获非字母、非“\n”字符。
这是我在此期间提出的解决方案,但我认为 Balthos 的回答更优越。
这里是作为布局 dxl 的一部分检索所有值的版本:
Skip allEnumValues(AttrDef ad) {
AttrType at = ad.type
Skip elements = create
int i
for(i = 0; i < at.size; i++) {
put(elements, i, (string at.strings[i]))
}
return elements;
}
Skip getSelectedValues(Object o, string attr, Skip allPossibleValues) {
Skip selectedValues = create
int i = 0
string str
for str in allPossibleValues do {
if(isMember(o.attr, str))
put(selectedValues, i++, str)
}
return selectedValues
}
void x(Module m, Object o) {
string attribute = "HAD_ComponentsASW"
Skip allValues = allEnumValues(find(m, attribute))
Skip selectedValues = getSelectedValues(o, attribute, allValues)
string str
for str in selectedValues do
display(str ",")
delete selectedValues
delete allValues
}
Module m = current Module
Object o = obj
x(m, o)
我工作的模块中有一个枚举类型的多值属性。
外观如下:
// as it appears in the attribute column
val1
vals-2
vals3
// below is what is written in my script to turn the contents this attribute
// into a string (for this particular object)
string ovp = o."AttribName" // I have assigned it to a string in this manner
如果我打印字符串,它会以列格式打印出来,就像它出现在属性列中一样。新行是如何在此字符串中定义的?
我想使用新的行定义将每个枚举值放入一个字符串数组(string arr[size], 为了清楚起见,因为我可能没有使用正确的条款)。
我确信有办法,但我使用 DXL 才两周,我不知道该怎么做,或者如果有另一种方法可能更容易。
我已经尽可能多地使用我知道的关键字进行搜索。
在此先感谢您的帮助或指导。与此同时,我会继续尝试,看看我能想出什么。我假设如果我找到答案,我可以用它更新这个问题。
因此,可能有更好的方法来执行此操作,即查询属性定义,然后使用 'isMember' 函数 - 但这种方法将 return 一个您请求的字符串数组。
Object o = current
string s = o."Test Enum" ""
int x = 0
int y = 0
int size = 0
if ( s != "" ) {
size++
}
for ( x = 0 ; x < length ( s ) ; x++ ) {
if ( s [ x ] == '\n' ) {
size++
}
}
string arr[size]
size = 0
for ( x = 0 ; x < length ( s ) ; x++ ) {
if ( s [ x ] == '\n' ) {
arr[ size ] = s [ y : x - 1 ]
y = x + 1
size++
}
}
arr[ size ] = s [ y : ]
注意 - 这首先检查数组的大小,然后定义它。多个选定的属性以“\n”作为分隔符,但最后一个条目没有。
我发现一种适用于字母的方法是使用正则表达式。首先,我还想指出,我预先声明我的字符串数组的大小为 10,我可能可以将其减少到 5,因为值集似乎永远不会超过 4。这不是重点,这就是我发现对我的信件有用的东西。
string ovs = o.vs "", ovp = o.vp "", tempstr = ""
Regexp alphabet = regexp"[a-zA-Z]"
int pp, i = 0
for (pp = 0; pp <= length(ovs); pp++) {
if(alphabet ovs[pp]"")
tempstr = tempstr "" ovs[pp] ""
else {
vsstrarr[i] = tempstr "";
i++; tempstr = ""
}
}
这确实有效,但我不知道是否需要多个 Regexp 变量来捕获非字母、非“\n”字符。
这是我在此期间提出的解决方案,但我认为 Balthos 的回答更优越。
这里是作为布局 dxl 的一部分检索所有值的版本:
Skip allEnumValues(AttrDef ad) {
AttrType at = ad.type
Skip elements = create
int i
for(i = 0; i < at.size; i++) {
put(elements, i, (string at.strings[i]))
}
return elements;
}
Skip getSelectedValues(Object o, string attr, Skip allPossibleValues) {
Skip selectedValues = create
int i = 0
string str
for str in allPossibleValues do {
if(isMember(o.attr, str))
put(selectedValues, i++, str)
}
return selectedValues
}
void x(Module m, Object o) {
string attribute = "HAD_ComponentsASW"
Skip allValues = allEnumValues(find(m, attribute))
Skip selectedValues = getSelectedValues(o, attribute, allValues)
string str
for str in selectedValues do
display(str ",")
delete selectedValues
delete allValues
}
Module m = current Module
Object o = obj
x(m, o)