我如何解决该准则 [英] How Do I Solved The Code

查看:95
本文介绍了我如何解决该准则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:Dim str As String =C:/ Ram / Ram1 / Ram2



这是一个硬编码输入,意味着我们想要的变量将其初始化为String。条件是我们只能使用一个打印选项。



输出:

C:/ Ram

C:/ Ram / Ram1

C:/ Ram / Ram1 / Ram2



请解决这个问题,为此我会感谢他/她。

Input : Dim str As String = "C:/Ram/Ram1/Ram2"

It is a hard coded input, means inside a variable we want to initialize this as a String. And the condition is we can use only one print option.

Output :
C:/Ram
C:/Ram/Ram1
C:/Ram/Ram1/Ram2

Please solve the question, for this i will be thankful to him/her.

推荐答案

最简单的方法是使用 string.Split [ ^ ]打破'/'处的字符串,然后从返回的数组中打印出来:

Easiest way is to use string.Split[^] to break the string at the '/' and then print it from the array that returns:
Dim str As String = "C:/Ram/Ram1/Ram2"
Dim parts As String() = str.Split("/"C)
Dim sb As New StringBuilder()
Dim sep As String = ""
For Each s As String In parts
    sb.AppendFormat("{0}{1}", sep, s)
    sep = "/"
    Console.Writeline(sb.ToString())
Next


这篇关于我如何解决该准则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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