在c#中拆分字符串而不使用拆分功能 [英] Split string in c# without using split function

查看:96
本文介绍了在c#中拆分字符串而不使用拆分功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我准备接受采访请帮我完成一些任务...

1.我需要一个程序来分解字符串而不使用溢出功能。



示例:

String S1 =Code,Project.C,om


我需要一个程序显示输出如

代码

项目

C

om




2.我想用c#显示字符串的最后两个字符。



示例:

字符串S2 =DotNetDeveloper

i需要输出才能显示最后三个字符



输出为





我希望我的问题清楚

Hi i am preparing for an interview please help me in some tasks...
1.I need a program to split the string with out using spilt function.

Example:
String S1="Code,Project.C,om"

I need a program to display an output like
Code
Project
C
om


2. I want to display the last two characters of my string using c#.

Example :
String S2="DotNetDeveloper"
i need an output to display only last three charaters

Output as
per

I hope my question is clear

推荐答案

有很多方法可以做到这一点:但是因为这有很多功课,我赢了;给你任何代码!

最明显的两个是:

1)使用IndexOf查找sperarator字符,然后使用SubString打破teh inpuit at那一点。重复直到IndexOf说没有更多的分隔符。

2)使用正则表达式匹配部分并返回一组匹配。将它们转换为单独的字符串。



第二个更简单:使用SubString。
There are a huge number of ways to do this: but as this smells heavily of homework, I won;t give you any code!
The most obvious two are:
1) Use IndexOf to find the sperarator character, and then use SubString to break teh inpuit at that point. Repeat until IndexOf says there are no more separators.
2) Use a regular expression to match the parts and return a set of matches. Convert these to individual strings.

The second one is even simpler: use SubString.


这篇关于在c#中拆分字符串而不使用拆分功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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