How can i put some spaces in my string in VB.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    How can i put some spaces in my string in VB.Net

    hello, i know some of your may think that this question have been answered thousand time. I agree but none of the solutions given worked for me.

    i have string like
    Code:
    Dim Test as String = "abc " & " def"
    what above code does is gives is "abc def" as output, what i want is "abc--------def" (where hash sign is spaces i need)

    i have tried
    Code:
    Dim Test as String = "abc----" & "----def"
    for some reason (dot)net only takes it as one single space. check above(1) example ,i gave two spaces but it got converted to one space.

    Code:
    Dim Test as String = "abc" & Char(9) & "def"
    doesn't work (found char(9) solution on internet)

    Code:
    Dim Test as String = "abc" & space(8) & "def"
    doesnot work

    I have tried another 10 different option but none seems to be working for me.

    Any help will be appreciated.

    Regards
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    Have you tried classic .NET string.Concat() ?

    Comment

    • pod
      Contributor
      • Sep 2007
      • 298

      #3
      is this for VB or ASP?

      Comment

      • jay123
        New Member
        • Sep 2008
        • 121

        #4
        Its VB.. (by the way whats minimum length of message that system allows here)

        Comment

        • Monomachus
          Recognized Expert New Member
          • Apr 2008
          • 127

          #5
          if it's VB and not VB.NET than u're in the wrong forum.

          Comment

          • pod
            Contributor
            • Sep 2007
            • 298

            #6
            I believe jay123 meant vb.net, my question should have been "is this for VB.NET or ASP.NET?"

            Comment

            • pod
              Contributor
              • Sep 2007
              • 298

              #7
              jay123, I would like to reproduce your problem but I need to know , on what do you display your string? on a caption, in a text box, on a messagebox?

              Comment

              • jay123
                New Member
                • Sep 2008
                • 121

                #8
                pod,

                Its vb.net, I have a label which need to show some text. The problem i am facing is like. i need to display the string as a label text as

                Code:
                Label.Text = "abc" & "bcf" & "efg"
                but their has to be tab(i am not sure if its tab difference but i need to give some space betwen them) difference between "abc" and "def". i have tried different ways but no gain.

                Jay

                Comment

                • pod
                  Contributor
                  • Sep 2007
                  • 298

                  #9
                  Sorry, I am unable to reproduce your problem. If you could attach all of your function's code as a text file (just the one file where your code resides), maybe we could find the problem.

                  here are a few more troubleshooting methods to try:

                  try changing the font of your label to "Courrier"

                  ..and also try this code (if you haven't already):
                  Code:
                  Label.Text = "abc" & "   " & "efg"

                  Comment

                  • jay123
                    New Member
                    • Sep 2008
                    • 121

                    #10
                    Hi Pod,
                    I have tried the given solution but thats the problem, no matter how many spaces you give. it only takes one space
                    ex
                    Code:
                     label1.text = "abc2 & "         " & "efg"
                    and
                    Code:
                    label1.Text = "abc" & " " & "efg"
                    gives same result.

                    my code is
                    Code:
                    lblRiskSummaryConditions.Text = Label1 & ": " & "No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode
                    where Label1 and Postcode are string variables.
                    now i want above string to be displayed as
                    Code:
                    Label1Text:      No. 1 RG1 7UQ
                    , instead it comes out as
                    Code:
                    Label1Text: No. 1 RG1 7UQ
                    (check space between ':' and 'No.'
                    Last edited by jay123; Sep 13 '10, 08:39 AM. Reason: Byte software doesnt take spaces

                    Comment

                    • pod
                      Contributor
                      • Sep 2007
                      • 298

                      #11
                      ... looking at your code here
                      Code:
                      lblRiskSummaryConditions.Text = Label1 & ": " & "No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode
                      the line above displays "Label1Text : No. 1 RG1 7UQ" ... as it should


                      now if you want more space between the ": " and the "No. " the line of code should be :
                      Code:
                      lblRiskSummaryConditions.Text = Label1 & ":        " & "No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode

                      or let's even simplify it a little more

                      Code:
                      lblRiskSummaryConditions.Text = Label1 & ":             No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode
                      let me know if I hit the nail on the head ...or on my finger :)

                      Comment

                      • jay123
                        New Member
                        • Sep 2008
                        • 121

                        #12
                        It doesnt work. We will assume that if we give space beteween two characters, it should take that space and display accordingly but strangely it only takes one space (no matter how many we give)
                        ex
                        Code:
                        lblRiskSummaryConditions.Text = Label1 & ":             No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode
                        and
                        Code:
                        lblRiskSummaryConditions.Text = Label1 & ": No. " & CInt(ChildRisk - Me.RiskId) & " - " & Postcode
                        gives same result as
                        Labeltext: No 1 RG1 7UQ

                        its really a classic one now. i never knew this gonna be that complicated..(i t just a space microsoft :) )

                        Comment

                        • pod
                          Contributor
                          • Sep 2007
                          • 298

                          #13
                          it's as if you had the function "Replace" running for everything, or some other function such as the TRIMALL macro http://www.mvps.org/dmcritchie/excel/join.htm#trimall.

                          If the problem is not in the portion of the script you displayed, one can only presume the problem resides in the remainder of your project.

                          Are you importing some DLLs, that might have text converting macros?

                          Can you post more code?

                          Comment

                          • jay123
                            New Member
                            • Sep 2008
                            • 121

                            #14
                            Its hard to figure out about DLL as its a big project and their are 100's of DLL floating around.

                            leave it mate, i'll post a solution if i manage to figure out what was causing the problem.

                            anyways thanks Pod for replying to this problem.

                            Comment

                            • pod
                              Contributor
                              • Sep 2007
                              • 298

                              #15
                              I wish you luck, and yes please do post the solution when you find it

                              merde!
                              (means best of luck)

                              P;oD

                              Comment

                              Working...