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. converting string with multiple values to string array

converting string with multiple values to string array

Scheduled Pinned Locked Moved C#
data-structureshelp
3 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.
  • G Offline
    G Offline
    gottimukkala
    wrote on last edited by
    #1

    Hi All, I am writing a function that accepts a string with values seperated by commas. I want to loop through all these values in the string and send each value as a string to another method. I am tring to do like this using arrays and loop through each value in the array: for this i am getting a error message private string InsertPublication(string structureId, string language, string title, string parentId, string contextId, int sortOrder, string pubIds) { string _response = ""; string[] pubId = new string[]; if (pubIds.Contains(",")) { for (int i = 0; i < pubIds.Length; i++) { int first_pId = pubIds.IndexOf(','); pubId[i] = pubIds.Substring(0, first_pId); } } else { pubId[0] = pubIds; } for (int i = 0; i < pubId.Length; i++) { if (parentId == "") { parentId = null; } string _elementId = _wdService.InsertPublication(structureId, language, title, parentId, contextId, sortOrder); if (_elementId.IndexOf("Error") < 0) { if (pubId[i].ToString() != "") { try { string _response2 = _wdService.JoinLeafPublication(structureId, _elementId, pubId[i].ToString()); _response = _response2; if (_response2.IndexOf("Success") == -1) { _response = "Failed"; } } catch { _response = "Failed"; } } else { _response = _elementId; } } else { _response = _elementId; } } return _response; } could any one please tell me. Thanks Aruna.G

    N F 2 Replies Last reply
    0
    • G gottimukkala

      Hi All, I am writing a function that accepts a string with values seperated by commas. I want to loop through all these values in the string and send each value as a string to another method. I am tring to do like this using arrays and loop through each value in the array: for this i am getting a error message private string InsertPublication(string structureId, string language, string title, string parentId, string contextId, int sortOrder, string pubIds) { string _response = ""; string[] pubId = new string[]; if (pubIds.Contains(",")) { for (int i = 0; i < pubIds.Length; i++) { int first_pId = pubIds.IndexOf(','); pubId[i] = pubIds.Substring(0, first_pId); } } else { pubId[0] = pubIds; } for (int i = 0; i < pubId.Length; i++) { if (parentId == "") { parentId = null; } string _elementId = _wdService.InsertPublication(structureId, language, title, parentId, contextId, sortOrder); if (_elementId.IndexOf("Error") < 0) { if (pubId[i].ToString() != "") { try { string _response2 = _wdService.JoinLeafPublication(structureId, _elementId, pubId[i].ToString()); _response = _response2; if (_response2.IndexOf("Success") == -1) { _response = "Failed"; } } catch { _response = "Failed"; } } else { _response = _elementId; } } else { _response = _elementId; } } return _response; } could any one please tell me. Thanks Aruna.G

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      If the input string is delimited, such as with a comma, then its easy to break it apart. string[] parts = input.split(',', StringSplitOptions.RemoveEmptyEntries);


      only two letters away from being an asset

      1 Reply Last reply
      0
      • G gottimukkala

        Hi All, I am writing a function that accepts a string with values seperated by commas. I want to loop through all these values in the string and send each value as a string to another method. I am tring to do like this using arrays and loop through each value in the array: for this i am getting a error message private string InsertPublication(string structureId, string language, string title, string parentId, string contextId, int sortOrder, string pubIds) { string _response = ""; string[] pubId = new string[]; if (pubIds.Contains(",")) { for (int i = 0; i < pubIds.Length; i++) { int first_pId = pubIds.IndexOf(','); pubId[i] = pubIds.Substring(0, first_pId); } } else { pubId[0] = pubIds; } for (int i = 0; i < pubId.Length; i++) { if (parentId == "") { parentId = null; } string _elementId = _wdService.InsertPublication(structureId, language, title, parentId, contextId, sortOrder); if (_elementId.IndexOf("Error") < 0) { if (pubId[i].ToString() != "") { try { string _response2 = _wdService.JoinLeafPublication(structureId, _elementId, pubId[i].ToString()); _response = _response2; if (_response2.IndexOf("Success") == -1) { _response = "Failed"; } } catch { _response = "Failed"; } } else { _response = _elementId; } } else { _response = _elementId; } } return _response; } could any one please tell me. Thanks Aruna.G

        F Offline
        F Offline
        Farhan Ali
        wrote on last edited by
        #3

        use Split method for strings which return an array e.g string[] str=strvalue.Split(','); now str will contain all values seperated by commas which u can pass to another functions after looping through it.

        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