473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

trim() function does not work

hi all,

i am having problems using the Trim() function in a program written in VB6. i'm getting my strings from reading a textfile line by line, but regardless of the trim function a couple of extra spaces are always included in the variable.

this is the code i use:
Expand|Select|Wrap|Line Numbers
  1.     Dim filepath As String
  2.     Dim FileNo As Long
  3.     Dim LineNo, i As Integer
  4.     Dim LineText As String
  5.  
  6.     FileNo = FreeFile ' Get next available file number.
  7.  
  8.     cdb.ShowOpen
  9.     filepath = cdb.FileName
  10.  
  11.     Open filepath For Input Access Read Shared As #FileNo
  12.         Do Until EOF(FileNo) ' Repeat until end of file...
  13.             Line Input #FileNo, LineText ' Read a line from the file.
  14.             LineNo = LineNo + 1
  15.  
  16.             txtFileName.Text = Trim(LineText) ' This line still leaves a couple of spaces at the end of the string in txtFileName.Text
  17.  
  18.             DoEvents ' Allow Windows to handle other tasks.
  19.         Loop
  20.     Close #FileNo
  21.  
why doesn't the Trim() function remove all tracing spaces?
Nov 13 '07 #1
3 8796
QVeen72
1,445 Expert 1GB
Hi,

Last Chars may be Chr(0) and not a Space. if they are Chr(0) then trim cannot remove those spaces. Instead use Replace Function :

Expand|Select|Wrap|Line Numbers
  1. txtFileName.Text = Replace(Trim(LineText),Chr(0),"")
  2.  
Regards
Veena
Nov 13 '07 #2
Hi,

Last Chars may be Chr(0) and not a Space. if they are Chr(0) then trim cannot remove those spaces. Instead use Replace Function :

Expand|Select|Wrap|Line Numbers
  1. txtFileName.Text = Replace(Trim(LineText),Chr(0),"")
  2.  
Regards
Veena
nope - didn't work. the strings are still trailed by spaces. could you please give me a simple function to split the string into a character array so i can check what characters they really are?

EDIT:
never mind - i took the last character, found out that it was chr(160) that i (also?) needed to replace, and when i did it worked. but the question remains... is there a better way to get the file extensions than using right(linetext,4)?
Nov 13 '07 #3
QVeen72
1,445 Expert 1GB
could you please give me a simple function to split the string into a character array so i can check what characters they really are?
Hi,

use this :

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. For i = 1 to Len(LineText)
  3.    Debug.Print Mid(LineText,i,1)   & "   Ascii =  "  & Asc(Mid(LineText,i,1))
  4. Next
  5.  
Regards
Veena
Nov 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mikael Hellström | last post by:
Hi all, i need to use the trim function trim("str","?") My question are. How do i remove the "return sign" from a string?? Regards Mikael
6
by: Dominic | last post by:
Here is the general problem: Information is taken from a form (consisting of text boxes, drop down lists et cetera) and submitted to an Access database. Before the data is inserted into the...
2
by: SK | last post by:
Trim function doesnt actually trim the spaces.Can anyone help
5
by: Dave Bovey | last post by:
I created a church database in Access 97 that contain the typical Name, Address, and Phone Number information fields. I had a number of different reports to print query data in different formats. ...
7
by: Sascha Herpers | last post by:
Hi, what is the difference between the trim function and the trim String-member? As far as I see it, both return the trimmed string and leave the original string unaltered. Is any of the two...
31
by: rkk | last post by:
Hi, I've written a small trim function to trim away the whitespaces in a given string. It works well with solaris forte cc compiler, but on mingw/cygwin gcc it isn't. Here is the code: char...
8
by: jonosborne | last post by:
Hi, Im sure the TRIM function works fine, otherwise there would be thousands of people worldwide kicking up a right fuss. But for some reason it is not returning the desired result. I have a...
4
by: ramaswamynanda | last post by:
Hello All, I have developed an application using Ms Access 2000. My client has Access 2003. I shipped him the code yesterday and he got an error hile running the application via the mdb file...
3
by: cmdolcet69 | last post by:
I ahve the following code that need to trim off the last character from a string dim STR as string If instr(STR <3 then LTrim(STR) THis code doesn;t work
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.