拆分字符串并存储到变量中 [英] Split string and store into variables

查看:64
本文介绍了拆分字符串并存储到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strOutput1 =some string

strOutput2 =somestring

strOutput =somestring



string result = strOutput1 + strOutput2 + strOutput;

返回结果;



i希望将strOutput带入变量并在客户端传递该变量side

strOutput1 = "some string"
strOutput2 = "somestring"
strOutput = "somestring"

string result = strOutput1 + strOutput2 + strOutput;
return result;

i want to take strOutput into a variable and pass that variable on client side

推荐答案

如果你要将你返回的值拆分为 result 那么你真的想要添加一个分隔符指示字符串的开始和结束位置:

If you want to split the value you return as result then you realy want to add a delimiter to indicate where the strings start and end:
strOutput1 = "some string"
strOutput2 = "somestring"
strOutput = "somestring"

string result = strOutput1 + "|" + strOutput2 + "|" + strOutput;
return result;



或更好:


Or better:

strOutput1 = "some string"
strOutput2 = "somestring"
strOutput = "somestring"

string result = string.Join("|", strOutput1, strOutput2, strOutput);
return result;



无论哪种方式,您都可以获得原始字符串:


Either way, you can then get the original strings back:

string[] parts = transferredString.Split('|');


这篇关于拆分字符串并存储到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆