1
Dim arr() As String
Dim a As Integer
Dim temp As String
Dim temp2 As String

a = 0

Open App.Path & "\EndOfB.txt" For Input As #1

Do While Not EOF(1)

    Line Input #1, temp
    temp2 = temp2 & "," & temp
    a = a + 1
    arr = Split(temp2, ",")

Loop 
Close #1

Guys how can i remove the character (") in the first and last array? because if i write in a textfile, the first and last string had this character ("). This is the sample output".

"08:01:04 08:16:06 10:52:06 11:52:21"

Thanks in advance Guys. :)

3
  • You're not writing it anywhere in that code. What do you mean "first and last array" - do you mean the first element in the array and the last elemnt in the array? Are you just writing out one string? Nothing makes any sense Commented Aug 11, 2016 at 3:46
  • oh sorry i didnt saw that it looks like 1 string. Yes i want to say is the first and last element in the array. just ignore the space and put new line. Commented Aug 11, 2016 at 5:54
  • every time is in a array. so it looks like arr(0) = "08:01:04 , arr(1) = 08:16:06 , arr(2) = 10:52:06 and arr(3) = 11:52:21" Commented Aug 11, 2016 at 5:55

3 Answers 3

1

Change your loop to

Do While Not EOF(1)

    Line Input #1, temp
    temp2 = temp2 & "," & temp
    a = a + 1
    arr = Split(temp2, ",")

    ' Strip first character from first array element
    arr(LBound(arr)) = Right$(arr(LBound(arr)), Len(arr(LBound(arr)) - 1))
    ' Strip last  character from last array element
    arr(UBound(arr)) = Left$(arr(UBound(arr)), Len(arr(UBound(arr)) - 1))


Loop 
Sign up to request clarification or add additional context in comments.

6 Comments

ive got an error "Variable required - cant assign to this expression"
What's your code and what line gives the error? You realize I'm just using your code - I have to believe you when you say "08:01:04 08:16:06 10:52:06 11:52:21" is the result of your variable... maybe show contents of "EndOfB.txt"
EndOfB.txt have no content. im just putting strings. im using it as a database.
SOoo ... again . what is YOUR code .... AND what line gives the error? where do you set temp and temp2 ? You're not making any sense now.
Updated answer. I added missing bracket around 'arr(LBound(arr))` and arr(UBound(arr)) - does that work now?
|
0

I had the same problem, I was able to just google it which is what you should do before asking but since I understand and had this problem myself for a little while I will give you a easy example of what do do.

Text1.Text = Mid(Text1.Text, 2)
Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)

I Hope this works for you, just replace text1.text with the name of the string you want to edit.

Comments

-1

Old thread but for the benefit of others here we go.

To remove a specific character or array of characters (if known) from the end of a string:

Text1.TrimEnd(Path.DirectorySeparatorChar)

This removes the operating system specific directory separator character. Simple and concise.

String.TrimEnd Method

Also related:

String.TrimStart Method

String.Trim Method

2 Comments

While the question is tagged vb.net, it is in fact about vb6, as it is clear from the code in the question and in the answers. People would routinely mistag their vba/vb6 questions with vb.net not realising they have nothing to do with each other. This answer pertains to vb.net, and is mostly a link-only answer.
You don't. The OP got VB6 answers because the code in the question is VB6 and not VB.NET. The wrong tag is therefore VB.NET.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.