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
  1. Home
  2. General Programming
  3. C#
  4. String Manipulation Question

String Manipulation Question

Scheduled Pinned Locked Moved C#
questioncsharpdata-structuresbeta-testinghelp
2 Posts 2 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.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    I am new to C# programming and I would like to ask for opinions on some coding procedures. :) I have a user input sentence that goes into “strValue”, (See below) from there it gets cut into separate words. I then need to add the first letter and “ay” to the end of the word. (So that it forms a pig Latin style word.)Then I need to restring them back into the same order that they were originally. I think I'm putting them into an array, and if so there is going to be no problem getting them back. :-O What I would like to know is “Would I be better off to place the string manipulations into separate constructors, methods, or maybe lumping them all together in either one”. :~ I know that each person does it differently, but I would like some feedback on what may be a better way to do this. :cool::rose: Thank you. private string strValue = " "; private string s = " "; //Cuts string into seperate words (char ?) char[] separator = { ' ' }; string[] s; s = strValue.Split(separator); foreach (string word in s) { Console.Write("{0}" + " ", word); } s = strValue.Insert(); //add first letter to end of word s = strValue.Insert(); //add "ay" to end of word s = strValue.Remove(0, 1); //Remove first letter

    A 1 Reply Last reply
    0
    • J JMOdom

      I am new to C# programming and I would like to ask for opinions on some coding procedures. :) I have a user input sentence that goes into “strValue”, (See below) from there it gets cut into separate words. I then need to add the first letter and “ay” to the end of the word. (So that it forms a pig Latin style word.)Then I need to restring them back into the same order that they were originally. I think I'm putting them into an array, and if so there is going to be no problem getting them back. :-O What I would like to know is “Would I be better off to place the string manipulations into separate constructors, methods, or maybe lumping them all together in either one”. :~ I know that each person does it differently, but I would like some feedback on what may be a better way to do this. :cool::rose: Thank you. private string strValue = " "; private string s = " "; //Cuts string into seperate words (char ?) char[] separator = { ' ' }; string[] s; s = strValue.Split(separator); foreach (string word in s) { Console.Write("{0}" + " ", word); } s = strValue.Insert(); //add first letter to end of word s = strValue.Insert(); //add "ay" to end of word s = strValue.Remove(0, 1); //Remove first letter

      A Offline
      A Offline
      Are Jay
      wrote on last edited by
      #2

      JMOdom wrote:

      What I would like to know is “Would I be better off to place the string manipulations into separate constructors, methods, or maybe lumping them all together in either one”.

      Placing the string manipulation within a function would make allot of since. Using a StringBuilder object would help with any processing overhead, only if your planning on calling your new function thousands of time but is still a good practice when manipulating strings. All and all it should be an efficient pig Latin creator.

      I'm listening but I only speak GEEK.

      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