LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Converting Strings to Integers

    Employee
    Posted 01-14-2010 12:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Iain Sanders

    Can somebody please advise what BRAINScript to use in a filter node to convert a data field's records from a string format to an integer and vis versa.

    Many thanks,

    Iain:


  • 2.  RE: Converting Strings to Integers

    Employee
    Posted 01-14-2010 13:12

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Example:
    v = 1
    w = "3"

    s = str(v) #s will have the string value "1"
    t = long(w) #t will have the integer value 3


  • 3.  RE: Converting Strings to Integers

    Employee
    Posted 01-14-2010 13:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Iain Sanders

    Hi There,

    I tried the following code:

    emit 'INSTALL1' = long('INSTALL') # 'INSTALL1'

    ...and I got the following error:

    Unexpected token ( = ) at line 26

    I basically want to convert all the values under the field name: INSTALL from strings to integers (the actual values appear as numbers in the table).

    Many thanks.

    Iain


  • 4.  RE: Converting Strings to Integers

    Employee
    Posted 01-14-2010 14:07

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Just take off the single quotes.

    emit INSTALL1 = long('INSTALL')

    or

    emit long('INSTALL') as INSTALL1

    The single quotes indicate that you want the VALUE of an input column. In this case, INSTALL1 is the NAME of an output column, so the single quotes are not necesary.

    You also have the option to do this:

    override emit long('INSTALL') as INSTALL

    Which would remove the input column INSTALL that is a string, and replace it with a new column INSTALL that is an integer.


  • 5.  RE: Converting Strings to Integers

    Employee
    Posted 01-14-2010 14:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Iain Sanders

    Hi again ,

    I got the following error log:

    ERROR processing data:
    could not convert to long integer: ' '

    Installing log (01/15/2010 10:38:03) ...
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "could not convert to long integer: ' '"; File: "\src\brain_d\ra_dev\code\source\expert\ToLongInte ger_ExprOp.cpp"; Line: 117; Context: "convertString()"
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "...exception seen in operator <long>"; File: "\src\brain_d\ra_dev\code\source\expert\ExprOperat or.cpp"; Line: 34; Context: "Salmon::NED::ExprOperator::apply()"
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "...exception seen in expression (long ...) starting on line 1"; File: "\src\brain_d\ra_dev\code\source\expert\Combinatio n_Expr.cpp"; Line: 210; Context: "Salmon::NED::Combination_Expr::evaluate()"
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "...exception seen"; File: "\src\brain_d\ra_dev\code\source\expert\BrainScrip tSet_ExprStmt.cpp"; Line: 80; Context: "BrainScriptSet_ExprStmt::_evaluate()"
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "...exception seen in statement 'bs-set', line 1"; File: "\src\brain_d\ra_dev\code\source\expert\ExprStatem ent.cpp"; Line: 56; Context: "Salmon::NED::Statement_Expr::evaluate()"
    2010-01-15 10:38:03; Level: 2; Type: 0; Desc: "...exception seen in context: { 0(in1):134 }"; File: "\src\brain_d\ra_dev\code\source\brain\ExprTableIo .cpp"; Line: 255; Context: "Salmon::ExprTableIo::processInputRows()"
    Uninstalling log (01/15/2010 10:38:03) ...


  • 6.  RE: Converting Strings to Integers

    Employee
    Posted 01-14-2010 16:41

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Iain Sanders

    I have managed to fix the problem - thank you for your help.

    I converted the empty spaces ' ' into NULL values, then the conversion worked.

    Many thanks - Iain