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. C#
  4. trim problems

trim problems

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 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.
  • A Offline
    A Offline
    asugix
    wrote on last edited by
    #1

    I'm using trim function and supposed to have my string trimmed. But my string remains same. For example : " hello", the result is : " hello". But I suppose the result is : "hello". Is anyone have same problem? Anyone knows the replacement function? If using VB, I don't have problem on string operation:confused:

    No one can prevent me to learn something

    L G 2 Replies Last reply
    0
    • A asugix

      I'm using trim function and supposed to have my string trimmed. But my string remains same. For example : " hello", the result is : " hello". But I suppose the result is : "hello". Is anyone have same problem? Anyone knows the replacement function? If using VB, I don't have problem on string operation:confused:

      No one can prevent me to learn something

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Are you assigning the result of Trim to the original string? Strings in .NET are immutable, which means that you must take the return value and assign it to a different (or the same) variable. Like that:

      string s = " hello";
      s = s.Trim();

      regards

      1 Reply Last reply
      0
      • A asugix

        I'm using trim function and supposed to have my string trimmed. But my string remains same. For example : " hello", the result is : " hello". But I suppose the result is : "hello". Is anyone have same problem? Anyone knows the replacement function? If using VB, I don't have problem on string operation:confused:

        No one can prevent me to learn something

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        It's impossible to definitely say what you are doing wrong without actually seeing the code. My guess is that you think that the method changes the string that it's applied on, when it actually returns a new string with the modified value: s.Trim() // creates a trimmed string and throws it away s = s.Trim() // creates a trimmed string and assigns it to the variable

        Despite everything, the person most likely to be fooling you next is yourself.

        A 1 Reply Last reply
        0
        • G Guffa

          It's impossible to definitely say what you are doing wrong without actually seeing the code. My guess is that you think that the method changes the string that it's applied on, when it actually returns a new string with the modified value: s.Trim() // creates a trimmed string and throws it away s = s.Trim() // creates a trimmed string and assigns it to the variable

          Despite everything, the person most likely to be fooling you next is yourself.

          A Offline
          A Offline
          asugix
          wrote on last edited by
          #4

          thank's. Maybe that's why sometimes it work and sometimes not

          No one can prevent me to learn something

          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