Results 1 to 17 of 17

Thread: Converting a String ???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Question

    Hi all,


    Code:
    Lyla = "Good morning Guys/Gals"
    
    Guys = "Good morning Lyla"
    
    Which = Right(Guys, 4)   ' ==> "Lyla"
    
    MsgBox which
    How can I convert Which from "Lyla" To Lyla Without the " "

    Thanx.

  2. #2
    Guest
    You mean get rid of the extra spaces? Use the Trim$ function.

    Code:
    MyString = Trim$(which)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Sorry Megatron.

    I meant How can I convert Which from "Lyla" To Lyla Without the "" Quotes So I can Call the Lyla Var.

    Thanx.





  4. #4
    Guest
    Code:
    Public Function replacestring(strstring As String, strwhat As String, strwith As String) As String
        Dim lngpos As Long
        Do While InStr(1&, strstring$, strwhat$)
            DoEvents
            Let lngpos& = InStr(1&, strstring$, strwhat$)
            Let strstring$ = Left$(strstring$, (lngpos& - 1&)) & Right$(strstring$, Len(strstring$) - (lngpos& + Len(strwhat$) - 1&))
        Loop
        Let replacestring$ = strstring$
    End Function
    
    Public Function trimchar(strtext As String, strchar As String) As String
        trimchar$ = replacestring(strtext$, strchar$, "")
    End Function
    
    Lyla2 = trimchar("" & Which & "", "" & Chr$(34) & "")


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Thanx Megatron & Matthew Gates.



  6. #6
    Guest
    So that is what you wanted? To remove the quotes?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Yes.

    So when I call:

    Msgbox which

    It would show Good morning Guys/Gals

    Thanx again.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Matthew Gates

    It didn't work !


  9. #9
    Guest
    I don't understand..works for me.

    You say you are trying to Trim(Remove) quotes. Here is an example.

    Code:
    Quotes = """Lyla"""
    Msgbox "Before:  " & Quotes
    Lyla2 = trimchar("" & Quotes & "", "" & Chr$(34) & "")
    Msgbox "After:  " & Lyla2
    Is that what you wanted? Or did I misunderstand you?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Dear Matthew Gates,

    Run this code in a Form_load:

    Code:
    Lyla = "Good morning Guys/Gals"
    
    Guys = "Good morning Lyla"
    
    Which = Right(Guys, 4)   
    
    'Toggle a breakpoint in your code 
    'and chech the value of which ???
    
    MsgBox which   ' ==> "Lyla"  with Quotes
    I want to use the returned value of which Without
    Quotes ??

    Sorry for not being very clear .

    Thanx again.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Red face

    Wow! 70 people !?

    Please help?


  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    I hope this simple example would clear things up

    Code:
    Dim Lyla As String
    Dim Guys As String
    Dim which As String
    
    Lyla = "Good morning Guys/Gals"
    
    Guys = "Good morning Lyla"
    
    which = Right(Guys, 4)   ' ==> "Lyla"
    
    
    Open file2 For Binary As fnum
     Put #fnum, , which 
    Close fnum
    I'm very sorry for being such a pain


  13. #13

  14. #14
    Guest
    Lyla,

    maybe a collection of strings comes close to what you are trying to do, although i don't understand why:

    '**********************************************************

    Private mcolString As New Collection

    Private Sub Form_Load()

    With mcolString
    .Add "Good morning Guys/Gals", "Lyla"
    .Add "Good morning Lyla", "Guys"
    End With

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    Set mcolString = Nothing

    End Sub

    Private Sub Command1_Click()

    With mcolString
    .Add Right(.Item("Guys"), 4), "which"
    MsgBox .Item(.Item("which"))
    End With

    End Sub

    '**********************************************************

    best regards

    Sascha

  15. #15
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Sascha
    Good Answer

    Lyla
    I can understand what you are trying to do but you are mixing things which are dynamic (ie the contents of strings) with something that is static (ie the names of variables).

    When you do this it is very easy to become not only confused but also very lost... hence the reason people didn't understant what you were attempting to do.

    I would say the best solution is that which Sascha gave you althought I would include error checking just in case the string you are searching for does not exist in the collection.

    Using this method you can have several key "phrases" that you can then assign strings to be replaced with and could do it on the fly.

    The use of the word Lyla as a variable simply says that it is a pointer to a string and it could be called Beetlejuice as far as anyone is concerned. When you compile your application the word Lyla is completely removed as it only has meaning when you are coding it.

    That is why we can basically use anything for a variable name... because all of those names are collected up and thrown out the window when it is compiled to be replaced with pointers that still do the job.... the name only has meaning to the programmer and that is why you really shouldn't and wouldn't use it inside your code as you were trying to do.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Sascha. That's IT


    Thank you all for helping.

  17. #17
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    my guess...
    Lyla is printing the string to a file
    and then reading the file for display, but
    when she does she is getting the file
    delimiters imposed on the string.

    this is not your answer but it will show you
    one way to get rid of the delimiter...
    Print statement instead of write..Private Sub Command1_Click()

    Lyla = "Good morning Guys/Gals"

    Guys = "Good morning Lyla"

    which = Right(Guys, 4)

    'Toggle a breakpoint in your code
    'and chech the value of which ???

    MsgBox which ' ==> "Lyla" with Quotes
    Dim file2
    file2 = "c:\a\a.txt"
    Dim fnum As Integer
    fnum = FreeFile

    Open file2 For Output As fnum
    Print #fnum, which
    Close fnum


    Open file2 For Input As fnum
    Input #fnum, which
    MsgBox which
    Close



    End Sub

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width