关于字符串表示 [英] about string representation
本文介绍了关于字符串表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有疑问要以以下格式显示字符串.
r s
ra sh
ram sha
拉姆·沙尔
ram sharm
ram sharma
I have question to display string in the following format .
r s
ra sh
ram sha
ram shar
ram sharm
ram sharma
推荐答案
这(已经提到过)闻起来很浓的作业:所以没有代码!
这并不困难:您需要做的只是:
1)阅读您的字符串.
2)将其拆分为单词(有一个名为Split的字符串方法可以做到这一点)
3)设置一个循环以遍历最长单词的每个字母(每个单词都将具有Length属性,找到最长的单词,然后使用for
循环.请记住要检查是否不会在简短单词的结尾.
4)从每个单词中提取一个短的(但长度增加)的片段(有一个称为Sube的字符串方法可以执行此操作)
5)打印结果:有一个名为Console的设备,它具有Write和WriteLine方法,可以做到这一点.
完成!
This (as has been mentioned) smells very strongly of homework: so no code!
It''s not difficult: all you need to do is:
1) Read your string.
2) Split it into words (There is a string method called Split that will do that)
3) Set up a loop to run through each letter of the longest word (each word will have a Length property, find the longest, and then use afor
loop. Remember to check you aren''t going to run over the end of the shorter words.
4) Extract a short (but increasing in length) segment from each word (there is a sting method calle Substring that will do it)
5) Print the result: there is a device called the Console, which has Write and WriteLine methods which will do that.
Done!
这篇关于关于字符串表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文