6 Replies - 466 Views - Last Post: 04 July 2013 - 12:30 PM Rate Topic: -----

#1 b mitsai  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 59
  • Joined: 09-November 12

[Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 10:30 AM

Hellowww community!
I know this sounds strange for you, as a vb programmer and developer, this functions makes me so mad because i never know when this works or not.

Let put this on parts:

- Trim : removes empaty spaces or white spaces in a String and return that already removed.

SO if i code like this:

Dim strMEM() As String = txtMemArray.Lines
        For Each s In strMEM '* s=string ; strMEM= String array
            s = Trim(s) '* this should return every string in the string array without spaces and it doesnt :s
            compiler.PutInMem(BP, s) '* you don't need to know but this str is copied to BP addrress (base pointer) of the memory that I'm simulating ;)/>/>
        Next



So, any ideas why? in my code i use a lot of this, but almost all the times it works, and now im stuck on this part.

Main question:
Where "Trim" functions actualy works and how?

-
fast code:
example:
dim str As String = "Hello I'm From Portugal "
msgbox(Trim(str))
'* the msgbox should be like: "HelloI'mFromPortugal"
'* and it works... easy code xD



thank you ! :D/>/>

This post has been edited by b mitsai: 04 July 2013 - 10:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: [Question]Trim RTrim LTrim - Where this work and where this don't

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 11:07 AM

bing search "msdn vb.net trim" -> gets you to the trim's docs.

http://msdn.microsof...y/d4tt83f9.aspx

which leads to:

Quote

Removes all leading and trailing occurrences of a set of characters specified in an array from the current String object.


It doesn't remove internal spaces - just the ends. If you want internal use the string's replace method.. have it look for spaces and replace with string.empty.
Was This Post Helpful? 1
  • +
  • -

#3 b mitsai  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 59
  • Joined: 09-November 12

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 11:47 AM

ok thanks so let me think
Serach every char and replace with String.Empty?
Ok this should work ;)
...
For Each s In strMEM
            s = s.Replace(" ", String.Empty)
            compiler.PutInMem(BP, s)
Next

it works :D
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 12:10 PM

View Postb mitsai, on 04 July 2013 - 12:47 PM, said:

Serach every char and replace with String.Empty?

Yes and no. You are not searching for every char. You are saying "Replace every string that is a space, with the empty string". You can also write this as s = s.Replace(" ", ""). Note that the thing to be replaced in this case is a string, as is the replacement, so the string to be replaced and the string to replace can be any length.

   Dim s as String = "Give me my walking shoes!"
   s = s.Replace ("wal","***")
   Console.Write(s)


This post has been edited by lar3ry: 04 July 2013 - 12:31 PM

Was This Post Helpful? 0
  • +
  • -

#5 b mitsai  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 59
  • Joined: 09-November 12

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 12:20 PM

meh i didnt mean that. I know what I did there.

Quote

Ok this should work ;)
...


I wrote "..." because i was working on it.
I completly forgot to change that line sorry but yeah, i used Replace method.

Thanks anyway ;)
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 12:21 PM

View Postb mitsai, on 04 July 2013 - 12:47 PM, said:

Serach every char and replace with String.Empty?

Yes and no. You are not searching for every char. You are saying "Replace every string that is a space, with the empty string". You can also write this as s = s.Replace(" ", ""). Note that the thing to be replaced in this case is a string, as is the replacement, so the string to be replaced and the string to replace can be any length.

   Dim s as String = "Give me my walking shoes!"
   s = s.Replace ("wal","***")
   Console.Write(s)



Edit: Sorry for the duplicate post. The first one posted, but never returned with any indication of it.

This post has been edited by lar3ry: 04 July 2013 - 12:26 PM

Was This Post Helpful? 0
  • +
  • -

#7 b mitsai  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 59
  • Joined: 09-November 12

Re: [Question]Trim RTrim LTrim - Where this work and where this don't

Posted 04 July 2013 - 12:30 PM

No problem sir :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1