作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
ESQL 没有像 Java 那样的内置字符串拆分功能,虽然它很容易构建静态函数并将 *.jar 添加到 IIB 类路径,但我工作过的几个站点全面禁止使用 Java。
那么 ESQL 中的高效字符串拆分器是什么样的。
最佳答案
主题的以下四种变体可用于拆分 ESQL 字符串。
我没有添加大量参数并以相当复杂的内部逻辑结束,而是选择了使用函数名称而不是标志的选项。
拆分字符串
不添加空字符串,但会添加包含多个空格的字符串。
CREATE PROCEDURE SplitString(
IN CompositeString CHAR, -- Composite string that needs to be split
IN Delimiter CHAR, -- Delimiter to be used when splitting the string
IN ArrayName CHAR, -- Name of the array for the results of the function
IN NewArray BOOLEAN, -- Use TRUE to clear a pre-existing array, FALSE appends new element
IN EnvRef REFERENCE -- Reference to Environment tree
)
BEGIN
IF NewArray THEN
DELETE FIELD EnvRef.SplitterArrays.{ArrayName};
END IF;
DECLARE Element CHAR;
DECLARE Remainder CHAR CompositeString;
DECLARE SplitterArrayRef REFERENCE TO EnvRef.SplitterArrays.{ArrayName};
IF NOT LASTMOVE(SplitterArrayRef) THEN
CREATE LASTCHILD OF EnvRef.SplitterArrays AS SplitterArrayRef NAME ArrayName;
END IF;
WHILE LENGTH(Remainder) <> 0 DO
IF POSITION(Delimiter IN Remainder) > 0 THEN
DECLARE Element CHAR SUBSTRING(Remainder BEFORE Delimiter);
IF LENGTH(Element) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE Element;
END IF;
SET Remainder = SUBSTRING(Remainder AFTER Delimiter);
ELSE
DECLARE Element CHAR Remainder;
IF LENGTH(Element) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE Element;
END IF;
SET Remainder = '';
END IF;
END WHILE;
END;
SplitStringTrim
修剪元素字符串中的前导和尾随空白。
不添加空字符串或空白字符串。
CREATE PROCEDURE SplitStringTrim(
IN CompositeString CHAR, -- Composite string that needs to be split
IN Delimiter CHAR, -- Delimiter to be used when splitting the string
IN ArrayName CHAR, -- Name of the array for the results of the function
IN NewArray BOOLEAN, -- Use TRUE to clear a pre-existing array, FALSE appends new element
IN EnvRef REFERENCE -- Reference to Environment tree
)
BEGIN
IF NewArray THEN
DELETE FIELD EnvRef.SplitterArrays.{ArrayName};
END IF;
DECLARE Element CHAR;
DECLARE Remainder CHAR TRIM(CompositeString);
DECLARE SplitterArrayRef REFERENCE TO EnvRef.SplitterArrays.{ArrayName};
IF NOT LASTMOVE(SplitterArrayRef) THEN
CREATE LASTCHILD OF EnvRef.SplitterArrays AS SplitterArrayRef NAME ArrayName;
END IF;
WHILE LENGTH(Remainder) <> 0 DO
IF POSITION(Delimiter IN Remainder) > 0 THEN
DECLARE Element CHAR TRIM(SUBSTRING(Remainder BEFORE Delimiter));
IF LENGTH(Element) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE Element;
END IF;
SET Remainder = SUBSTRING(Remainder AFTER Delimiter;
ELSE
DECLARE Element CHAR TRIM(Remainder);
IF LENGTH(Element) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE Element;
END IF;
SET Remainder = '';
END IF;
END WHILE;
END;
SplitStringAddEmpty
向 SplitterArray 添加空元素,确保至少有一个元素。
保留空白。
CREATE PROCEDURE SplitStringAddEmpty(
IN CompositeString CHAR, -- Composite string that needs to be split
IN Delimiter CHAR, -- Delimiter to be used when splitting the string
IN ArrayName CHAR, -- Name of the array for the results of the function
IN NewArray BOOLEAN, -- Use TRUE to clear a pre-existing array, FALSE appends new element
IN EnvRef REFERENCE -- Reference to Environment tree
)
BEGIN
IF NewArray THEN
DELETE FIELD EnvRef.SplitterArrays.{ArrayName};
END IF;
DECLARE Element CHAR;
DECLARE Remainder CHAR CompositeString;
DECLARE EndsWithDelimiter BOOLEAN ENDSWITH(Remainder, Delimiter);
DECLARE SplitterArrayRef REFERENCE TO EnvRef.SplitterArrays.{ArrayName};
IF NOT LASTMOVE(SplitterArrayRef) THEN
CREATE LASTCHILD OF EnvRef.SplitterArrays AS SplitterArrayRef NAME ArrayName;
END IF;
IF LENGTH(Remainder) = 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE '';
ELSE
WHILE LENGTH(Remainder) <> 0 DO
IF POSITION(Delimiter IN Remainder) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE SUBSTRING(Remainder BEFORE Delimiter);
SET Remainder = SUBSTRING(Remainder AFTER Delimiter);
ELSE
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE Remainder;
SET Remainder = '';
END IF;
END WHILE;
IF EndsWithDelimiter THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE '';
END IF;
END IF;
END;
SplitStringAddEmptyTrim
向 SplitterArray 添加空元素,确保至少有一个元素。
修剪元素字符串中的前导和尾随空白。
CREATE PROCEDURE SplitStringAddEmptyTrim(
IN CompositeString CHAR, -- Composite string that needs to be split
IN Delimiter CHAR, -- Delimiter to be used when splitting the string
IN ArrayName CHAR, -- Name of the array for the results of the function
IN NewArray BOOLEAN, -- Use TRUE to clear a pre-existing array, FALSE appends new element
IN EnvRef REFERENCE -- Reference to Environment tree
)
BEGIN
IF NewArray THEN
DELETE FIELD EnvRef.SplitterArrays.{ArrayName};
END IF;
DECLARE Element CHAR;
DECLARE Remainder CHAR TRIM(CompositeString);
DECLARE EndsWithDelimiter BOOLEAN ENDSWITH(Remainder, Delimiter);
DECLARE SplitterArrayRef REFERENCE TO EnvRef.SplitterArrays.{ArrayName};
IF NOT LASTMOVE(SplitterArrayRef) THEN
CREATE LASTCHILD OF EnvRef.SplitterArrays AS SplitterArrayRef NAME ArrayName;
END IF;
IF LENGTH(Remainder) = 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE '';
ELSE
WHILE LENGTH(Remainder) <> 0 DO
IF POSITION(Delimiter IN Remainder) > 0 THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE TRIM(SUBSTRING(Remainder BEFORE Delimiter));
SET Remainder = SUBSTRING(Remainder AFTER Delimiter);
ELSE
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE TRIM(Remainder);
SET Remainder = '';
END IF;
END WHILE;
IF EndsWithDelimiter THEN
CREATE LASTCHILD OF SplitterArrayRef NAME 'Element' VALUE '';
END IF;
END IF;
END;
关于ibm-integration-bus - 用于拆分定界字符串的 ESQL 字符串拆分器函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56097056/
我正在实现谱聚类算法,我必须确保矩阵(拉普拉斯矩阵)是半正定矩阵。 检查矩阵是否为正定矩阵 (PD) 就足够了,因为可以在特征值中看到“半”部分。矩阵非常大(nxn,其中 n 是几千的数量级)所以特征
我是一名优秀的程序员,十分优秀!