Click here to Skip to main content
15,881,789 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Comments
Maciej Los 24-Nov-14 6:18am    
We can't read in yoour mind or direct from your screen. Please, be more specific and provide more details...
Bittu14 24-Nov-14 6:56am    
1) Input is already given, means we can't take the input from user.
2) To print the output we can use only one print statement option, means we
will print the output using only one print statement.
Bittu14 24-Nov-14 7:14am    
Did You please tell me the actual answer? It will be helpful for me.

1 solution

Easiest way is to use string.Split[^] to break the string at the '/' and then print it from the array that returns:
VB
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
 
Share this answer
 
v2
Comments
Richard MacCutchan 24-Nov-14 6:22am    
Shouldn't parts be private?
OriginalGriff 24-Nov-14 6:50am    
You may have to add

Imports System.Text
Bittu14 24-Nov-14 7:01am    
Thanks.
But I need the above output not the below one -
C:
C:/Ram
C:/Ram/Ram1
C:/Ram/Ram1/Ram2
OriginalGriff 24-Nov-14 7:04am    
So tweak it!
It's not exactly complicated - and it is your homework, after all...
Bittu14 24-Nov-14 7:07am    
Ok. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900