Need more Progarmming Help

soulslicer

Tank
Joined
Mar 16, 2007
Messages
4,623
Reaction score
12
Okay, I'm been trying to get this concept to work but failing.

Very Simply: My Objective:

I have a function that can receive not just strings, but a whole ARRAY intself. Say receive an array that has 5 strings..

and I want to change each of those strings say .ToLower(), .Trim() etc.

and send that back to the Main Function as a fully changed Array.

and this can easily be repeated on other string arrays

So I tried this :

Code:
 static string StringEditor(string[] stringer)
        {
            for(int i=0;i<stringer.Length;i++)
            {
                stringer[i].ToLower();
                stringer[i].Trim();
                
            }
            return stringer[];
        }
     static void Main(string[] args)
        {

 string[] power = { "He llo", "Boy", "GAGAGA" };
            string[] newe = StringEditor(power);
            foreach (string yy in newe)
            {
                Console.WriteLine(yy);
            }
            Console.ReadLine();

}

unfortunately, the error message is that i cannot implicitly convert an arraystring to a string in the second line of Main(). and also that I cannot return stringer[]

is there anyway you guys can help me resolve this, or write something for me
 
Three things:

First, your StringEditor method is returning a singular string, not an array, so that shouldn't even compile.

Second, assuming this is C# or Java, method parameters are passed "byref", or as a reference, which means you don't need to return a value in StringEditor - you'd be making changes to the array you pass in.

Third, you aren't actually making any changes to the array - you need to assign the result of the method, and you can actually do it in one line like this: stringer = stringer.ToLower().Trim();

One last bit - if you *are* using C#, you can do the whole thing in a single line using LINQ:

var newe = power.Select(s => s.ToLower().Trim()).ToArray();
 
Back
Top