Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
here's the code with C# built in functions, how do i do it without built in functions?

C#
string str = Console.ReadLine();
           string strrev = "";
           char[] punctuation = new char[] { ' ', ',', '.','?', '!'};
           char[] inputAsChars = str.ToCharArray();

           string temp = "";
           foreach (char c in inputAsChars)
           {
               if (punctuation.Contains(c))
               {
                   char[] tx = temp.ToCharArray();
                   Array.Reverse(tx);
                   temp = new string(tx);
                   strrev += temp + c;
                   temp = "";
               }
               else
                   temp += c;
           }
           Console.WriteLine(strrev);
           Console.ReadLine();
Posted
Comments
[no name] 12-Apr-14 17:44pm    
"how do i do it without built in functions", well you would look up what each of the functions does and then write a ton of code to replace the functions, for no benefit whatsoever.
Nelek 12-Apr-14 18:25pm    
This is suspiciously very similar to other question done today. Have a look there
[no name] 12-Apr-14 18:32pm    
Suspiciously similar to the exact same OP.
Steve44 12-Apr-14 21:15pm    
This sounds suspiciously like a homework question, therefor no use of utility functions (like Array.Reverse), but learning how to implement these kind of functions.

Dear OP, if this is the case, please put in the effort to solve the problem like Wes' first posting: read the documentation and write the code to implement your version of the built-in functions. This is for YOUR benefit, you will learn a lot and get a feeling for programming, edge cases and testing your functions. Asking for a solution will rob you of this opportunity to gain experience and hone your skills of using the software developers tool box.

1 solution

How about
C#
string input = Console.ReadLine();
var query = Regex.Matches(input, @"\W+|(\w+)")
                 .Cast<Match>()
                 .Select(m=>m.Groups[1].Success
                            ? new string(m.Groups[1].Value.Reverse().ToArray())
                            : m.Value);
Console.WriteLine(string.Join(string.Empty, query));

Cheers
Andi
 
Share this answer
 
Comments
Steve44 12-Apr-14 21:16pm    
That uses even more built-in functionality :-)
Andreas Gieriet 13-Apr-14 14:16pm    
So, what do you consider a built-in function? This is no-sense, sorry. Even it is a homework, this is meaningless - people should stand on the shoulders of others, i.e. know the libraries, not re-invent the wheel!
Built-in to the language is the basic types, their basic operators - they base on the CLR. Then you have the language keiywords and some reserved identifiers, the statement blocks and argument lists, etc. Everything else is libraries. Some libraries are shipped with the installation for basic IO, etc. No library is built-in - it all bases on the language as decribed above.
What is now the goal of this? What exactly do you want?
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900