Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2013
    Posts
    3

    Smile Unanswered: VB6 Find in string

    Hi
    I'm having trouble converting file formats,
    i have this line: time="2013-07-03 17:13:47" id="1" name="ANDY" workcode="0" status="0" authority="0X55" card_src="from_check"


    I need it to read: 2013-07-03 17:13:47,1,ANDY,

    I have been trying to individually find the values in the "" but im struggling
    Any ideas?

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    A really noddy way to approach it that should get you the format you need:

    Replace quotes followed by a space with a comma.

    Replace time=" with an empty string.
    Repeat for other headings
    George
    Home | Blog

  3. #3
    Join Date
    Sep 2013
    Posts
    3
    Quote Originally Posted by gvee View Post
    A really noddy way to approach it that should get you the format you need:

    Replace quotes followed by a space with a comma.

    Replace time=" with an empty string.
    Repeat for other headings
    OK that sounds good!
    Could you direct me to the code to find, and the code to replace?
    Any online examples or msdn would be brill. Thanks

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    do you need all the rest of the line as well, the workcode, authority etc.....
    what you could do is run a series of statements that clear out the crap using the replace statement

    Code:
    'lets assume your data is in a variable called MyVariable
    myvariable = replace(trim(myvariable), '"', '') 'first strip out any " signs. the trim fucntion strips off leading and or trailing spaces
    'then strip out any other stuff
    myvariable = replace(myvariable, 'time', '')
    myvariable = replace(myvariable, 'id', '')
    myvariable = replace(myvariable, 'name', '')
    myvariable = replace(myvariable, 'status', '')
    myvariable = replace(myvariable, 'authority', '')
    myvariable = replace(myvariable, 'card_src', '')
    myvariable = replace(myvariable, '=', '')
    'the reason for doing this way is it caters for additional spaces so it will work with time = ", time=",time= ", time ="
    myvariable = replace(myvariable, '  ', ' ') 'remove any double spaces
    'ok so now we have gone from:-
    'time="2013-07-03 17:13:47" id="1" name="ANDY" workcode="0" status="0" authority="0X55" card_src="from_check"
    'to:-
    '2013-07-03 17:13:47 1 ANDY 0 0 0X55 from_check
    then add the commas to separate the columns
    replace (MyVariable," ", ",", 18) 'replace any space with a comma starting at character position 18
    'we shoudl now have:-
    '2013-07-03 17:13:47,1,ANDY,0,0,0X55,from_check
    the above is untested. its not spellchecked its just as is. so you may need to tweak it to make it work.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2013
    Posts
    3
    Your a Star! that worked prefectly!
    I had to use Replace(myvariable, Chr$(34), "") to replace the quotations but other than that worked perfectly!

    Thanks again

Posting Permissions

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