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. Trim String Array

Trim String Array

Scheduled Pinned Locked Moved C#
questioncomdata-structurestestingbeta-testing
4 Posts 4 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

    I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) 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=;

    D L P 3 Replies Last reply
    0
    • A Arcdigital

      I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) 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=;

      D Offline
      D Offline
      Dr Emmett Brown
      wrote on last edited by
      #2

      This should work: string[] finalResult = new string[apiresult.Length]; for (int i = 0; i < apiresult.Length; i++) { finalResult[i] = apiresult[i].Substring(apiresult[i].IndexOf('=')+1); } Don't be afraid of loops. :) Cheers

      rotter

      modified on Saturday, August 16, 2008 11:41 PM

      1 Reply Last reply
      0
      • A Arcdigital

        I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) 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=;

        L Offline
        L Offline
        lisan_al_ghaib
        wrote on last edited by
        #3

        Hi! Try using this string [] tokens = myString.split (new char[] {';' , '='}); foreach (string s in tokens) { //do something to s; } DONT use a fixed array string !!!!

        1 Reply Last reply
        0
        • A Arcdigital

          I posted this a few days ago, but it got kinda lost. I want to have the final array NOT contain the part before the equals sign (result, etc...) 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=;

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          It didn't get lost, you just didn't look for it http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2677761[^]

          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