Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to calculate size of terms and put this size before terms in text file is replace space in vb.net
Posted
Comments
Andreas Gieriet 31-Mar-12 11:34am    
Please rephrase the problem. Your title and description does not make any sense to me.
Did you already try something out? Please show that, so that we can help.
Cheers
Andi
Richard MacCutchan 31-Mar-12 11:39am    
Why do you keep repeating this same vague question rather than explaining exactly what problem you are trying to solve? Spend some time thinking about exactly what you want to do, and then edit the above question with some clear details of what that problem is, and where you are stuck.
OriginalGriff 31-Mar-12 11:53am    
Or just give us a proper example: input and output.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

If my extrasensory perception works the best, You want to replace an empty space before the words that the space lenght is equal to the word.
For example:

I am a developer. ==> I  am a         developer


Then:
C#
//C#
public string MakeSpace(string text)
{
    StringBuilder sentenceBuilder = new StringBuilder();
    string[] strings = text.Split((char)32);

    foreach (string s in strings)
    {
        if (string.IsNullOrEmpty(s))
            continue;

        StringBuilder spaceBuilder = new StringBuilder();
        for (int i = 0; i < s.Length; i++)
        {
            spaceBuilder.Append(" ");
        }

        sentenceBuilder.Append(string.Format("{0}{1}", spaceBuilder.ToString(), s));
    }

    return sentenceBuilder.ToString();
}


VB
'VB.Net
Public Function MakeSpace(text As String) As String
    Dim sentenceBuilder As New StringBuilder()
    Dim strings As String() = text.Split(CChar(32))

    For Each s As String In strings
        If String.IsNullOrEmpty(s) Then
            Continue For
        End If

        Dim spaceBuilder As New StringBuilder()
        For i As Integer = 0 To s.Length - 1
            spaceBuilder.Append(" ")
        Next

        sentenceBuilder.Append(String.Format("{0}{1}", spaceBuilder.ToString(), s))
    Next

    Return sentenceBuilder.ToString()
End Function
 
Share this answer
 
v5
Comments
Maciej Los 1-Apr-12 16:56pm    
My 5!
Shahin Khorshidnia 1-Apr-12 17:27pm    
Thank you very much Iosmac

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