如何从主字符串中获取子字符串? [英] How to get a substring from a main string ?

查看:126
本文介绍了如何从主字符串中获取子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我的主字符串为
字符串str1 ="a b c e f g h i j k l m n o p q r,s t u v w x y z";

我想输出为

str2 ="a b c e f g h i j k l m n o p q r";
str3 ="s t u v w x y z";


我想要我的问题的代码

for example if i have a main string of
string str1="a b c e f g h i j k l m n o p q r, s t u v w x y z";

i want output as

str2="a b c e f g h i j k l m n o p q r";
str3="s t u v w x y z";


i want code for my question

推荐答案

,所以您有一个字符串,并希望对其执行一些操作?您知道什么..NET有一个字符串类,如何阅读其一些文档?

甚至更好的是,您是否考虑购买一本有关C#的书并进行研究,它会教给您开始使用新语言时应了解的所有知识.

:)
so you have a string and want to perform some operations on it? You know what, .NET has a string class, how about reading some of its documentation?

And even better, did you consider buying a book on C# and studying that, it would teach you everything you should know when starting to use a new language.

:)


这很好,您想要用于此的代码.但是,您是否尝试过获得想要的东西?如果有人为您编写此代码,您将怎么办?

您是否不知道有一种名为Substring的方法可以轻松实现您的目的.请尝试使用substring方法,如果遇到任何困难,请告知我们.

请发布困难.不要忘记. :-D
This is good that you want the code for this. But did you try a bit to get what you want? What would you do if someone writes this code for you?

Don''t you know there is a method called Substring that easily serves your purpose. Please try the substring method and let us know if you get any difficulty.

Please post the difficulty. Dont forget. :-D


既然您发布了编程问题,那么像程序员一样表现如何?您需要做什么?

步骤1,找到逗号.
步骤2,将逗号之前的所有内容存储在str2中
步骤3,将逗号后的所有内容存储在str3

那么,您可以采取什么措施呢?字符串是由什么组成的?它不是char数组吗?

因此,在找到逗号之前,您不能一一遍遍数组吗?

找到它之后,那又如何呢?

这是一个非常基本的过程,如果您对此有疑问,则需要参加一个正式的课程.如果您是正规班的学生,则需要安排一名导师.当我上大学时,我是一名导师,其中一个可以帮助您,第二个可以通过给他们钱来帮助他们.
Since you are posting a programming question, how about acting like a programmer? What is it that you need to do?

Step 1, Find the comma.
Step 2, Store everything before the comma in str2
Step 3, Store everything after the comma in str3

So, what is available for you to do this? What is a string made up of? Isn''t it an array of char?

So, can''t you go one by one through the array until you find the comma?

Once you''ve found it, then what?

This is such a basic process that if you are having trouble with this, you need to take a formal class. If you are in a formal class, then you need to arrange for a tutor. When I was in college, I was a tutor, and one, it helps you out, and two, it helps them out by giving them money.


这篇关于如何从主字符串中获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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