SPONSORS:






User Tag List

Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Dec 2001
    Location
    Billings, MT, USA
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    shaving off white space in variables

    Hello,
    I'm trying to truncate the trailing spaces in a variable used for comparing the value in the database. The code I'm currently using is a raw comparison, but I'm finding out that the database is chopping off unnecessary whitespace at the end of data on the sql load.

    Here is my code snippet:

    [ ] //test for match in database
    [-] if(saction != "DELETE" && susername != "NO_VALUE_FOUND")
    [ ] ssql_query = "select fphone from hotjobs.person where pindex = '"+sppindex+"'"
    [ ] squery_result = db_query(hdbc, sline, ssql_query)
    [ ]
    [ ] //error if NULL found on database search
    [+] if(squery_result==NULL)
    [ ] ierror++
    [ ] print("Error: xml CONTACTFAX value [{sline}] not found in database for record: [{sppindex}]")
    [ ] break
    [ ]
    [ ] //error if match not made
    [+] if(db_match(sipf, sppindex, squery_result, sline)==FALSE)
    [ ] ierror++
    [ ] break

    [ ] ////////////////////////////////////////////////////////////////////////////////
    [ ] //** function db_query()
    [ ] //** runs a query based on global variables
    [-] string db_query(handle hdbc, string sline, string ssql_query)
    [ ] handle hstmnt
    [ ] boolean bstatus
    [ ] string stemp
    [ ]
    [ ] hstmnt = DB_ExecuteSql (hdbc, ssql_query)
    [ ]
    [ ] bstatus = DB_FetchNext (hstmnt, stemp)
    [ ]
    [-] if(bstatus==TRUE)
    [ ] DB_FinishSQL(hstmnt)
    [ ] return stemp
    [-] else
    [ ] DB_FinishSQL(hstmnt)
    [ ] print("Value: [{sline}] not found in database.")
    [ ] return "NO_VALUE_FOUND"
    [ ]
    [ ] ////////////////////////////////////////////////////////////////////////////////
    [ ] //** function db_match()
    [ ] //** runs a query of db and compares value found in input file to result
    [-] boolean db_match(string sipf, string sppindex, string squery_result, string svar)
    [-] if(squery_result == svar)
    [ ] return TRUE
    [-] if(squery_result != svar)
    [ ] print("Error: value: [{svar}] in: [{sipf}] not equal to db value: [{squery_result}]")
    [ ] print("ppindex searched: {sppindex}")
    [ ] return FALSE
    [ ]


    Here are two error's from the .res file:

    [ ] Error: value: [ 918-495-1469] in: [input.txt] not equal to db value: [918-495-1469]
    [ ] ppindex searched: P425159GH

    [ ] Error: value: [603 NE campus St. ] in: [input.txt] not equal to db value: [603 NE campus St.]
    [ ] ppindex searched: P658097JA


    Any idea's as to how to shave whitespace from the variable? I can do it in C, but I'm not sure how in 4test.
    Thanks,
    Clay

    ------------------
    There is no try, only do. -Yoda
    Clay Givens
    Yahoo! QA Engineer

  2. #2
    Senior Member
    Join Date
    Jul 2001
    Location
    Westford, MA, USA
    Posts
    160
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: shaving off white space in variables

    A couple of options:

    1. You can always use * and ? wildcard characters in your string comparison, if you want. In MatchStr, the order of the arguments is sometimes significant.

    2. If you want to exercise tighter control over the comparison to avoid false matches, you can use:
    sMyString = Ltrim(sMyString)
    sMyString = Rtrim(sMyString)
    or if you want to save the original string then you'd do:
    sMyNewerString = Ltrim(sMyString)
    sMyNewestString = Rtrim(sMyNewerString)

    AG


    ------------------

  3. #3
    Member
    Join Date
    Dec 2001
    Location
    Billings, MT, USA
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: shaving off white space in variables

    Thanks for showing me these functions. That worked marvelously.
    -Clay

    ------------------
    There is no try, only do. -Yoda
    Clay Givens
    Yahoo! QA Engineer

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 12:45 PM.

Copyright BetaSoft Inc.