Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Maintain whitespace between strings

Maintain whitespace between strings

Scheduled Pinned Locked Moved Visual Basic
help
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4510968
    wrote on last edited by
    #1

    Hello friends, I tried converting lower case char to upper case and vice versa it works fine with the following code Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() case 1 Input : ABCdef Output: abcDEF case 2 Input :ABC def GHI Output:abccDEFFFghi Desired Output:abc DEF ghi The issue is maintaining the whitespace between the strings, with the current code the the whitespaces are replaced by the previous charcter in the output. I like the whitespaces between the strings to be maintained . Thanks In Advance Praveen

    C B L J 4 Replies Last reply
    0
    • U User 4510968

      Hello friends, I tried converting lower case char to upper case and vice versa it works fine with the following code Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() case 1 Input : ABCdef Output: abcDEF case 2 Input :ABC def GHI Output:abccDEFFFghi Desired Output:abc DEF ghi The issue is maintaining the whitespace between the strings, with the current code the the whitespaces are replaced by the previous charcter in the output. I like the whitespaces between the strings to be maintained . Thanks In Advance Praveen

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Member 4514218 wrote:

      If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32)

      What an ugly, ugly mess. Char.IsAlpha is what you need, from memory. And Char.ToLower. How about abc = abc.ToLower()

      Member 4514218 wrote:

      If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b

      The core flaw in your logic is that you need another else. else b = a Otherwise, anyting that is not a lower or uppercase character, is lost. you look like you're coming from VB6, that's where all the nasty habits are coming from. Forget VB6, learn to use VB.NET properly. And, learn to use the debugger, if you stepped through this code, you'd have seen in no time what the issue was.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      1 Reply Last reply
      0
      • U User 4510968

        Hello friends, I tried converting lower case char to upper case and vice versa it works fine with the following code Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() case 1 Input : ABCdef Output: abcDEF case 2 Input :ABC def GHI Output:abccDEFFFghi Desired Output:abc DEF ghi The issue is maintaining the whitespace between the strings, with the current code the the whitespaces are replaced by the previous charcter in the output. I like the whitespaces between the strings to be maintained . Thanks In Advance Praveen

        B Offline
        B Offline
        binjafar
        wrote on last edited by
        #3

        very simple...just add one 'Else'... as below...! Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) Else b = a End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() Enjoy!

        U 1 Reply Last reply
        0
        • U User 4510968

          Hello friends, I tried converting lower case char to upper case and vice versa it works fine with the following code Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() case 1 Input : ABCdef Output: abcDEF case 2 Input :ABC def GHI Output:abccDEFFFghi Desired Output:abc DEF ghi The issue is maintaining the whitespace between the strings, with the current code the the whitespaces are replaced by the previous charcter in the output. I like the whitespaces between the strings to be maintained . Thanks In Advance Praveen

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          Dim ca As Char() = TextBox1.Text.ToCharArray
          TextBox1.Text = ""
          For Each c As String In ca
          Select Case Char.IsUpper(c)
          Case True
          TextBox1Text &= c.ToLower
          Case False
          TextBox1.Text &= c.ToUpper
          Case Else
          TextBox1.Text &= c
          End Select
          Next

          My advice is free, and you may get what you paid for.

          1 Reply Last reply
          0
          • U User 4510968

            Hello friends, I tried converting lower case char to upper case and vice versa it works fine with the following code Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() case 1 Input : ABCdef Output: abcDEF case 2 Input :ABC def GHI Output:abccDEFFFghi Desired Output:abc DEF ghi The issue is maintaining the whitespace between the strings, with the current code the the whitespaces are replaced by the previous charcter in the output. I like the whitespaces between the strings to be maintained . Thanks In Advance Praveen

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Member 4514218 wrote:

            Dim b As Char

            replace this by Dim b As Char = a the logic is: output char equals input char, except when it is an upper/lowercase letter. And please use PRE tags to keep code readable. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            1 Reply Last reply
            0
            • B binjafar

              very simple...just add one 'Else'... as below...! Dim abc As String Dim xyz As String = String.Empty Dim a As Char Console.WriteLine("Enter The String") abc = Console.ReadLine() For Each a In abc Dim b As Char If Asc(a) > 64 And Asc(a) < 91 Then b = Chr(Asc(a) + 32) ElseIf Asc(a) > 96 And Asc(a) < 123 Then b = Chr(Asc(a) - 32) Else b = a End If xyz = xyz + b Next Console.WriteLine(xyz) Console.ReadLine() Enjoy!

              U Offline
              U Offline
              User 4510968
              wrote on last edited by
              #6

              Thanks binjafar It is simple and effective Regards Praveen

              B 1 Reply Last reply
              0
              • U User 4510968

                Thanks binjafar It is simple and effective Regards Praveen

                B Offline
                B Offline
                binjafar
                wrote on last edited by
                #7

                my pleasure.... :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups