ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * @category 取子字符串 * @param instr * 入参|原字符串|{@link java.lang.String} * @param begin * 入参|起始位置(0开始)|{@link int} * @param end * 入参|结束位置(-1时取之后的所有)|{@link int} * @param outstr * 出参|返回子串|{@link java.lang.String} * @return 0 失败<br/> * 1 成功<br/> */ @InParams(param = { @Param(name = "instr", comment = "原字符串", type = java.lang.String.class), @Param(name = "begin", comment = "起始位置(0开始)", type = int.class), @Param(name = "end", comment = "结束位置(0时取之后的所有)", type = int.class) }) @OutParams(param = { @Param(name = "outstr", comment = "返回子串", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) @Component(label = "字符串截取", style = "判断型", type = "同步组件", comment = "取子字符串", version = "1.0.0", deprecated = false, date = "2018-01-22 04:23:48") public static ResultBase P_substr(String instr, int begin, int end) { if (instr == null) { return ResultBase.newFailureResult("TPTS1004", "原字符串不能为空"); } if (begin < 0 || (end > 0 && end < begin) || begin >= instr.length()) { return ResultBase.newFailureResult("TPTS1005", "输入起止位置不正确,begin=" + begin + ",end=" + end + ",原字符串长度=" + instr.length()); } if (end > 0 && end >= instr.length()) return ResultBase.newSuccessResult(instr.substring(begin, instr.length())); if (end > 0) { return ResultBase.newSuccessResult(instr.substring(begin, end)); } return ResultBase.newSuccessResult(instr.substring(begin)); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/fc/eb/fcebb6b20a773c8f3776588a02c1376e_1872x890.png) # 参数说明及示例 ## 入口参数 原字符串:输入一串字符串,示例: `"qweasdzxc"` 起始位置(0开始):开始截取的位置,示例: `2` 结束位置(0时取之后的所有):结束截取的位置,示例: `5` ## 出口参数 返回子串:截取的字符串,示例: `__INNER__["result"]`