Olukayode Oluwole
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(str ing inputstring)
{
string s1 = inputstring;
string[] s2 = s1.Split('@');
foreach (string s3 in s2)
{
// Console.WriteLine(s3);
}
string outusername = LoginDetails.staticusercod e = 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(Us erNameValu e.Text);
UserNameValue.Text = LoginDetails.staticusercod e;
CompanyCodeValue.Text = LoginDetails.staticcompany ;
See where i have the error below
How do i call the processor and place the 2 values in Username.Text and Companyname.Text
Grateful for any Help
olukay
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(str
{
string s1 = inputstring;
string[] s2 = s1.Split('@');
foreach (string s3 in s2)
{
// Console.WriteLine(s3);
}
string outusername = LoginDetails.staticusercod
string outcompanyname = LoginDetails.staticcompany
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(Us
UserNameValue.Text = LoginDetails.staticusercod
CompanyCodeValue.Text = LoginDetails.staticcompany
See where i have the error below
How do i call the processor and place the 2 values in Username.Text and Companyname.Text
Grateful for any Help
olukay
ASKER
So what would be the correct syntax ??
Thanks
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.
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.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Thanks for your help
Olukay
Olukay
You are welcome : )
Here comes a bonus:
Add a @ char at the end of inputstring.
Like this:
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
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('@');
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.
Ermmm. Think long and hard about that.
ASKER
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
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:
Having no @ char and adding one @ char is securing you from having no second entry.
You see?
string outcompanyname = LoginDetails.staticcompany = s2[1]
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?
ASKER
Szvonko you are simply great. Thanks
public Tuple<string, string> GetUsernameCompanyName(string inputstring)
than that in your code snippet - StringSpliterProcessor2
I guess that is your problem