Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

I do I retrieve 2 values from a library tuple processor

In my c# application I need to split  a string   VOKE@NAUTILUS  into 2  strings  (VOKE  and NAUTILUS)

I want to use the tuple  below  taking

input as  VOKE@NAUTILUS   and   output  as

outputvariable1 = VOKE
outputvariable2 = NAUTILUS

 The Library Processor  is shown below

[public Tuple<string, string> GetUsernameCompanyName(string inputstring)
        {
            string s1 = inputstring;
            string[] s2 = s1.Split('@');
            foreach (string s3 in s2)
            {
                //  Console.WriteLine(s3);
            }
            string outusername = LoginDetails.staticusercode = s2[0];
            string outcompanyname = LoginDetails.staticcompany = s2[1];
           
            return new Tuple<string, string>(outusername, outcompanyname);
        }[/code]

I  want to initialize the processor   and get the variable into 2 screen variable as below

  StringSpliterProcessor2 processor2 = new StringSpliterProcessor2(UserNameValue.Text);
  UserNameValue.Text = LoginDetails.staticusercode;
   CompanyCodeValue.Text = LoginDetails.staticcompany;

See  where i have the error below

User generated image
How do i call the processor and place the 2 values in  Username.Text  and  Companyname.Text

Grateful  for any Help

olukay
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Here you have a different name
public Tuple<string, string> GetUsernameCompanyName(string inputstring)
than that in your code snippet - StringSpliterProcessor2

I guess that is your problem
Avatar of Olukayode Oluwole

ASKER

So what would be the correct syntax  ??

Thanks
The correct syntax is NOT to mix string split and LoginDetails assignment.

And after you split the input text from UserNameValue then you immediately assign to same field the first part of the string!

Common! Cleanup your concept and then is your coding more readable and resolves from itself.

Removing syntax error does not help you with your logic errors.




Ok  thanks.  Tried to resolve the issue as advised.

Please see below

User generated image
How do i get the 2 varianles  realusername and realcompanyname  

back from the tuple


Olukay
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Look up tuples in the help files.  It seems like you have just copied a piece of code from somewhere and don't know the basics about classes it uses.
Thanks  for your help

Olukay
You are welcome  :  )

Here comes a bonus:
Add a @ char at the end of inputstring.
Like this:
public Tuple<string, string> GetUsernameCompanyName(string inputstring)
        {
            string s1 = inputstring+"@";
            string[] s2 = s1.Split('@');

Open in new window


You guess why?
This way you always get two elements in s2 and don't have to worry about whether the inputstring has an @ char or not.
You will learn the benefit of it ;-)

Greetings,
Zvonko




>>This way you always get two elements in s2 and don't have to worry about whether the inputstring has an @ char or not.

Ermmm.  Think long and hard about that.
It will be good to know what extra benefits one derives. But apart from
This is there a way to confirm that @ is part of string before the split.

That's

Olukay
The extra benefit is that you do not have to catch the error in following statement when there is no @ char is in the inputstring:
string outcompanyname = LoginDetails.staticcompany = s2[1]

Open in new window

There is no second entry if you have no @ char. If you have two @ chars then you have three entries but that is not a problem.
Having no @ char and adding one @ char is securing you from having no second entry.

You see?


Szvonko you are simply great. Thanks