如何将字符串拆分为两个并存储在两个变量中 [英] How to split a string into two and store in two variables

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

问题描述

大家好,

如果字符串长度大于45,我需要拆分字符串并将其存储到变量中。



假设字符串是

Hi all,
I need to split a string if the string length is greater than 45 and store that it into a variable.

Suppose string is "

Two Thousand Four Hundred Ninety Three Dirhams and Twenty Eight Fils 

- 这里我需要将字符串拆分为第五空格并将拆分部分存储到两个变量。

如何做到这一点。非常感谢任何帮助。



我尝试了什么: < br $> b $ b

" -Here I need to split the string at 5th space and store the splitted parts to two variable.
How to do this.Any help will be really appreciated.

What I have tried:

string lab7 = label7.Text.Length.ToString();




if (int.Parse(lab7) >= 45)
          {
                      //here need to store the splitted strings to variables
          }

推荐答案

您需要阅读有关字符串函数的文档,其中一些允许您获取一部分内容string。
You need to read the documentation about string functions, a few of them allow you to get a part of a string.


我们不做你的作业:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



所以首先要看一个正则表达式(搜索对于正则表达式c#)并获取 Expresso 的副本[ ^ ] - 它是免费的,它会检查并生成正则表达式,或者查看字符串处理函数:string.Split,string .IndexOf和string.Substring方法。



亲自试试,你可能会发现它并不像你想象的那么难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

So start by looking at either a Regex (Search for "Regular Expressions c#") and get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions, or look at the string handling functions: string.Split, string.IndexOf, and string.Substring methods.

Try it yourself, you may find it is not as difficult as you think!


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

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