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.  Count how many times a charater apears in a string

    Employee
    Posted 07-30-2015 02:32

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

    Originally posted by: jramada

    Hi,

    I have a string that contains 4 to 8 itens that I want to extract, but the number of itens is variable (split by #) in each line, ex:

    pagina=View General Contract Calls#mask=true#dataInicio=2014/08/01#dataFim=2014/10/01#servicos=Dados;Dados Roaming;Dados VPN;UMTS;Webphone;
    pagina=View General Account Calls#mask=true#dataInicio=2014/05/01#dataFim=2014/05/31#prefixos=Internacional;#servicos=Voz;
    pagina=View General Account Calls#mask=true#dataInicio=2014/07/30#dataFim=2014/10/28#creditos=CUG;

    What I want to get:
    First Line
    CONSULT_TYPE = View General Contract Calls
    MASK = true
    START_DATE = 2014/08/01
    END_DATE = 2014/10/01
    SERVICES = Dados;Dados Roaming;Dados VPN;UMTS;Webphone;

    Second Line
    CONSULT_TYPE = View General Account Calls
    MASK = true
    START_DATE = 2014/05/01
    END_DATE = 2014/05/31
    PREFIXS = Internacional
    SERVICE = Voz

    Third Line
    CONSULT_TYPE = View General Account Calls
    MASK = true
    START_DATE = 2014/07/30
    END_DATE = 2014/10/28
    CREDITS = CUG

    The solution I found was to split the file according to the number of fields, number of times the "#" appears in the string and then extract the fields (because I cant get the slip function to work with this diferent number of fields in each line).

    But I dont know how I can count the number of "#" charateres in the string.
    Can anyone help me?

    Thanks


  • 2.  RE: Count how many times a charater apears in a string

    Employee
    Posted 07-30-2015 13:55

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

    Originally posted by: stonysmith

    Two methods:
    L1=strlen(pagina)-strlen(pagina.replace("#",""))

    L2=len(pagina.split("#"))


  • 3.  RE: Count how many times a charater apears in a string

    Employee
    Posted 07-30-2015 14:34

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

    Originally posted by: ryeh

    It seems like your data is pretty well structured. If you had an ID for each of those records, you can split by # to get the fields, and then split by = to get the field name and field value.
    Attachments:
    breakRecordsIntoFields.brg