企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 ``` /** * <b>方法描述:</b> 字符串编码转换 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 18:18:26 <br/> * * @param text * 入参|待转字符串|{@link java.lang.String} * @param charset * 入参|编码|{@link java.lang.String} * @param newString * 出参|新编码字符串|{@link java.lang.String} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "字符串编码转换", style = "判断型", type = "同步组件", comment = "将输入字符串转换层指定编码", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 06:18:26") @InParams(param = { @Param(name = "text", comment = "待转字符串", type = java.lang.String.class), @Param(name = "charset", comment = "编码", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "newString", comment = "新编码字符串", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_changeCharset(String text, String charset) { if (charset == null || !Charset.isSupported(charset)) { return ResultBase.newFailureResult("TPTS1020", "编码方式输入错误,charset=" + charset); } if (StringUtil.isBlank(text)) { return ResultBase.newFailureResult("TPTS1021", "转换字符串不能为空"); } try { String str = new String(text.getBytes(), charset); return ResultBase.newSuccessResult(str); } catch (UnsupportedEncodingException e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTS1022", "字符串编码转换错误:" + AppLog.errorMsg(e)); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/4a/65/4a65decc0403c53d93cbd8f6c80ed920_1868x893.png) # 参数说明及示例 ## 入口参数 待转字符串:输入字符串,示例: `"你好,世界"` 编码:设置字符串的编码格式,示例: `"gbk"` ## 出口参数 新编码字符串:经过转码后的字符串,示例: `__INNER__["result"]`