c# - Splitting only returns System.String[] instead of actual value -
i've searched while , still haven't found anything.
my problem is, want split value, delivered textbox 1 appears.
string t1 = textbox1.text; string[] split = t1.split(new char[] {'1'});
i'm delivering value written in variable textbox. problem is, won't display stuff comes after 1, should in split method. instead displays system.string[]. have ?
edit:
complete code part of program:
{ string t1 = textbox1.text; string[] split = t1.split(new char[] { }); textbox1.text = split.tostring(); if (split.length == 2) textbox4.text = split[1]; url = "https://www.google.de/search?q=" + textbox3.text + "&um=1&client=" + split[1] + "-a&rls=org.mozilla:de:official&hl=de&" + textbox2.text + "=lnms&sa=x&ei=re2yud-rcyic4gthw4gwaq&ved=0cakq_auoaa&biw=1920&bih=951 textbox4.text = url; }
i think assigning result textbox this:
textbox2.text = split.tostring();
the tostring()
converting string[] split
array string, default returns name of type, in case system.string[]
.
in order able use it, split
array should have @ least 2 items in it; namely, substrings in textbox separated /
characters.
i suspect want use characters after /
so:
if (split.length >= 2) textbox2.text = split[1];
string.split()
work this:
if input text was: "abcd/efgh"
, split
be:
split[0] == "abcd"; split[1] == "efgh";
and if input text was: "abcdefg"
, split
be:
split[0] == "abcdefg"; // there no split[1]
and if input text was: "ab/cd/ef"
, split
be:
split[0] == "ab" split[1] == "cd" split[2] == "ef"
note these last 2 cases both have split.length != 2
.
what want last case, there 2 (or more) /
characters in input?
[edit] looking @ last update, line of code wrong:
textbox1.text = split.tostring();
it should be:
if (split.length > 0) textbox1.text = split[0];
read first part of answer above explanation split.tostring()
does!
also, line wrong:
string[] split = t1.split(new char[] { });
it should
string[] split = t1.split(new [] {'/'});
you didn't specify character split on. comments below anwser, assume want split on '/'
.
finally! line starting with:
url = "https: ...
uses split[1]
need protect if:
if (split.length > 1) url = "https: ... else url = "<didn't work!>"; // or something! :)
Comments
Post a Comment