String Manipulation Question
-
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
-
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
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.