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.  Replace Text

    Employee
    Posted 03-22-2016 03:05

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

    Originally posted by: lauraw_21

    Please can someone help me, i need to use a Replace Text node to replace ampersands in the entire data set to say + instead?

    Thanks


  • 2.  RE: Replace Text

    Employee
    Posted 03-22-2016 04:26

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

    Originally posted by: awilliams1024

    Hi,

    I'm not familiar with the Replace Text node so perhaps another contributor will post an example but, in the mean time, here is an example that uses a regular expression to replace the ampersand character with another character.
    Copy and paste the following code into the BRE canvas

    Regards,
    Adrian

    node:Replace_Specified_Character
    bretype:core::Filter
    editor:Label=Replace Specified Character
    editor:sortkey=56f1219738a04ba8_2
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:CharacterToReplace=@
    prop:ReplacementCharacter=+
    prop:Script=<<EOX
    _fields =	if "{{^Fields=^}}" == "" then inputFields(1) else "{{^Fields=^}}".split(",")
    _rp_non_alphanum = {{^Replace non-alphanumeric=true^}}
    _rp_non_alphanum_with = "{{^Replace non-alphanumeric with=^}}"
    _rm_multispace = {{^Replace multi-space with single=true^}}
    _nullEmpty = {{^Null empty strings=true^}}
    
    _value = ""
    _header = ""
    if firstExec then {
    row_id =0
    }
    output 1 {emit _value, _header, row_id where false}
    
    i = 0 
    while i < _fields.len() {
    	_header = _fields.getItem(i)
    	
    	# Replace the amp characters with plus character
    	_value = field(_fields.getItem(i)).str().regexSubstituteI("[{{^CharacterToReplace^}}]","{{^ReplacementCharacter^}}")
    		
    		
    	do output 1 {emit  _value, _header, row_id}
    	i = i + 1 
    }
    
    row_id = row_id + 1
    EOX
    editor:XY=350,120
    editor:propdef=Fields|string|Input||None
    editor:propdef=CharacterToReplace|string|Input||Not Blank
    editor:propdef=ReplacementCharacter|string|Input||Not Blank
    editor:propdoc=Fields=Comma separated list of fields. If not specified, all fields are processed.
    editor:propdoc=CharacterToReplace=The character to be replaced.
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=The following special characters need to be prefixed by "\\"  (without the quotes).
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace= [ . $ { * ( \ + ) | ? < >  ^
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=
    editor:propdoc=CharacterToReplace=To replace the backslash character "\" enter "\\\\" (without the quotes).
    editor:propdoc=ReplacementCharacter=The character used as the replacement for the specified character
    end:Replace_Specified_Character
    
    node:Remove_The_Row_ID
    bretype:core::Filter
    editor:Label=Remove The Row ID
    editor:sortkey=56f123da315a10c4
    input:@40fd2c74167f1ca2/=Pivot__Data_To_Names.4ca9ea197eed4a1a
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    
    emit *
    exclude row_id
    
    EOX
    editor:XY=550,120
    end:Remove_The_Row_ID
    
    node:Pivot__Data_To_Names
    bretype:core::Pivot - Data To Names
    editor:sortkey=56f123b325181022
    input:@4ca9ea0e77f858a8/=Replace_Specified_Character.40fd2c7420761db6
    output:@4ca9ea197eed4a1a/=
    prop:DataField=_value
    prop:GroupBy=<<EOX
    row_id
    EOX
    prop:NamesField=_header
    editor:XY=450,120
    node:GroupByPath
    bretype:::GroupByPath
    editor:shadow=4cd2e31a25825f1b
    input:@4ccfdae429e85cb5/=
    output:@4ccfdae4585258de/=
    node:DataToNamesWithGroupBy
    bretype:::DataToNamesWithGroupBy
    editor:shadow=4cd2e31a003467e9
    input:@4cceefe2650d45e1/=
    input:@4cceefe45c596005/=
    output:@4cceeff7142d3549/=
    end:DataToNamesWithGroupBy
    
    node:Sort
    bretype:::Sort
    editor:shadow=4cd2e31a71bb6ba4
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort
    
    node:Agg
    bretype:::Agg
    editor:shadow=4cd2e31a69415a14
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    output:@4cd003f34b1437c4/=
    end:Agg
    
    node:Bypass
    bretype:::Bypass
    editor:shadow=4cd2e31a078b0885
    input:@4b467f7e129d45c1/=
    input:@4b467f830ffe047b/=
    output:@40fd2c7436717256/=
    end:Bypass
    
    node:Agg_2
    bretype:::Agg
    editor:shadow=4cd2e31a0deb376a
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    end:Agg_2
    
    end:GroupByPath
    
    node:NoGroupByPath
    bretype:::NoGroupByPath
    editor:shadow=4cd2e31a55c8124a
    input:@4ccfdae429e85cb5/=
    output:@4ccfdae4585258de/=
    node:DataToNamesNoGroupBy
    bretype:::DataToNamesNoGroupBy
    editor:shadow=4cd2e31a1d6263ef
    input:@4cceefe2650d45e1/=
    input:@4cceefe45c596005/=
    output:@4cceeff7142d3549/=
    end:DataToNamesNoGroupBy
    
    node:Agg
    bretype:::Agg
    editor:shadow=4cd2e31a1bbb492b
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    end:Agg
    
    end:NoGroupByPath
    
    node:Bypass
    bretype:::Bypass
    editor:shadow=4cd2e31a1cd03eb3
    input:@4ccfdb241245012a/=
    input:@4ccfdb25174c47e7/=
    output:@40fd2c7436717256/=
    end:Bypass
    
    end:Pivot__Data_To_Names
    
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=56f11e0c33980ae0
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    color:string, id:int,type:string,rand:int,junk:string
    Red@,1,primary,27959,okay
    Green,2,@primary,7138,"""Let's Go"", he said"
    Blue,3,primary,15790,may@be
    Yellow,4,secondary@,17809,no@pe
    Cy@an,5,secondary,16901,Not@@NULL
    
    EOX
    editor:XY=160,120
    end:Static_Data


  • 3.  RE: Replace Text

    Employee
    Posted 03-22-2016 08:16

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

    Originally posted by: ryeh

    Here's a Replace Text sample:

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=56f1632f16197203
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    a,b,c
    &,1,2
    1,2&,3
    &,&,&&3
    EOX
    editor:XY=130,100
    end:Static_Data
    
    node:Replace_Text
    bretype:core::Replace Text
    editor:sortkey=56f163581fd26cee
    input:@40fd2c743f6973ec/=Static_Data.40fe6c55598828e5
    output:@40fd2c7469010b53/=
    prop:Fields=<<EOX
    *=rule1
    EOX
    prop:Rules=<<EOX
    rule1::
    &->+
    EOX
    editor:XY=260,100
    end:Replace_Text


  • 4.  RE: Replace Text

    Employee
    Posted 03-30-2016 02:36

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

    Originally posted by: awilliams1024

    Another alternative approach would be to use one of the new 'accelerators' that are available to users of LAE 6.1 / LAE 6.0 who have installed LAL 6.1.44.0 / LAL 6.0.44.0.

    In particular, the 'Easy Text Replace' accelerator enables you to replace all occurrences of a text string in a specified field with a new text string (using case-sensitive matching).

    EasyReplace_accelerator_example.brg

    The accelerators can be made visible in the node palette for the current data flow by adding the accelerators as a base library:

    In the BRE menu click on Graph -> Edit Base Libraries...
    Then click on the 'New' icon in the Base Libraries dialogue panel
    Type 'accelerators' into the new empty row (without the quotes) and click OK
    The accelerators should now be visible in the different categories of the palette.

    To add the accelerators to the palette for all data flows perform the following:

    In the BRE menu click on Tools -> Preferences
    In the BRE Preferences panel click on the 'Libraries' tab
    Click on the 'New' icon in the 'Default Base Libraries' pane
    Overwrite the 'new' library name with 'accelerators' (without the quotes)
    Click OK
    Close BRE and reopen it - the accelerators should now be visible in the palette.

    Should you want to remove the accelerators from the palette, follow the initial steps you used to add them for the current data flow or all data flows and when the list of base libraries is displayed select the accelerator entry and click on the 'Delete' icon and click OK