Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help with Trimming String Array Please!

Help with Trimming String Array Please!

Scheduled Pinned Locked Moved C#
questioncomdata-structurestestingbeta-testing
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arcdigital
    wrote on last edited by
    #1

    Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array

    string[] apiresult = new string[25];
    char[] splitter = { ';' };
    apiresult = result.Split(splitter);

    My question is, how do I trim the string array so it just contains success 1 Bob etc... instead of result=success userid=1 firstname=Bob etc...

    result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;

    C N A 3 Replies Last reply
    0
    • A Arcdigital

      Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array

      string[] apiresult = new string[25];
      char[] splitter = { ';' };
      apiresult = result.Split(splitter);

      My question is, how do I trim the string array so it just contains success 1 Bob etc... instead of result=success userid=1 firstname=Bob etc...

      result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      you need to take each string and split it on the =. So, this is a two step thing. you need to iterate over the one set and split each string to get the second set.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      1 Reply Last reply
      0
      • A Arcdigital

        Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array

        string[] apiresult = new string[25];
        char[] splitter = { ';' };
        apiresult = result.Split(splitter);

        My question is, how do I trim the string array so it just contains success 1 Bob etc... instead of result=success userid=1 firstname=Bob etc...

        result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Othr than CG suggested, you can try this also

        string[] apiresult = result.Split(';', '=');
        List<string> expectedList = new List<string>(apiresult.Length / 2);
        for (int i = 1; i < apiresult.Length; i = i +2)
        {
        expectedList.Add(apiresult[i]);
        }

        Splitting is done in single step here.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        1 Reply Last reply
        0
        • A Arcdigital

          Hey, I was wondering if anyone can help me with trimming a string array. I am calling an API that returns this (At bottom of post). I am then using this to convert that into a string array

          string[] apiresult = new string[25];
          char[] splitter = { ';' };
          apiresult = result.Split(splitter);

          My question is, how do I trim the string array so it just contains success 1 Bob etc... instead of result=success userid=1 firstname=Bob etc...

          result=success;userid=1;firstname=Bob;lastname=Smith;companyname=Smith Enterprises;email=bsmith@boostplatform.com;address1=1 Smith Drive;address2=;city=Bobtown;state=Bobstate;postcode=12345;country=US;phonenumber=419-123-4567;notes=TESTING ACCOUNT!!;password=bsmith;status=Active;credit=1010.00;taxexempt=;language=;lastlogin=No Login Logged;billingcid=0;domainemails=;generalemails=;invoiceemails=;productemails=;supportemails=;

          A Offline
          A Offline
          Arcdigital
          wrote on last edited by
          #4

          Thanks, but I don't want the firstname, lastname, etc... part of the array. Just the actual answers (Bob, Smith, etc...)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups