C
C#2y ago
JJ

❔ [WPF] C# Grammer, find string

Hi I wanna find TexeBox's string what im typing to TextBlock's string. sender is TextBox class, linq's x is text block class. first, Im just wanna extract sender's string as you can see 'd' not {System.Windows.Controls.TextBox: d} , I forgot this grammer that extract only string without type name. and then wanna compare to between two sentence(textBlock's text and textBox's text) as find function for searching sender's string which is or isn't in TestBox'string.
31 Replies
JJ
JJOP2y ago
FindAll error
TheRanger
TheRanger2y ago
string texeBoxString = (sender as TextBox).Text; calling ToString() on a textbox would just return it's type name so you need to cast it, then access it's Text property
JJ
JJOP2y ago
oh yes thanks !
TheRanger
TheRanger2y ago
can u give an example on what ur trying to find? you want to check if for example es is in Test ?
JJ
JJOP2y ago
yes about FindAll private void Search_TexeChanged(object sender, TextChangedEventArgs e) { string textBoxString = (sender as TextBox).Text; foreach (Linq x in linq) { string textBlockString = (x.textBlock as TextBlock).Text; string findStr = Array.FindAll(textBoxString, element => element.Equals(textBlockString)); } }
TheRanger
TheRanger2y ago
what do u expect FindAll returns?
JJ
JJOP2y ago
I just thought retrun value is that the same string if i do typing "asd" in TextBox, if in textBlock just have "as" then return "as"
TheRanger
TheRanger2y ago
ud probably off better using string's Contains method instead
BugzyGeek
BugzyGeek2y ago
If you want to check if a particular substring is in a string you can use the Contains function.
JJ
JJOP2y ago
is there return string at c#? if it is not, I would return index number if same
TheRanger
TheRanger2y ago
i dont see why you need to return the string, just use the string from the textbox who's value is as
JJ
JJOP2y ago
this is also having problem
TheRanger
TheRanger2y ago
what problem? i cant read the error message
JJ
JJOP2y ago
Oh, Im doing implement toyproject this
JJ
JJOP2y ago
Im making Sticky Notes like picture
BugzyGeek
BugzyGeek2y ago
are you looking for the index "as" starts from?
JJ
JJOP2y ago
TheRanger
TheRanger2y ago
well it tells you No overload for method 'FindIndex' takes 1 arguments
JJ
JJOP2y ago
Im looking for comparing between string
TheRanger
TheRanger2y ago
string's Contains method should work for you
MODiX
MODiX2y ago
TheRanger#3357
REPL Result: Success
"asd".Contains("as")
"asd".Contains("as")
Result: bool
True
True
Compile: 486.987ms | Execution: 27.185ms | React with ❌ to remove this embed.
TheRanger
TheRanger2y ago
i assume u wanna filter your sticky notes to show notes who contains your input, right?
JJ
JJOP2y ago
private void Search_TexeChanged(object sender, TextChangedEventArgs e) { string textBoxString = (sender as TextBox).Text; foreach (Linq x in linq) { string textBlockString = (x.textBlock as TextBlock).Text; if(String.Equals(textBoxString, textBlockString)) { MessageBox.Show(textBlockString); } } } yes, I try myself
TheRanger
TheRanger2y ago
nope that wont work
JJ
JJOP2y ago
I found it ,
MODiX
MODiX2y ago
TheRanger#3357
REPL Result: Success
String.Equals("as", "asd")
String.Equals("as", "asd")
Result: bool
False
False
Compile: 510.925ms | Execution: 26.215ms | React with ❌ to remove this embed.
TheRanger
TheRanger2y ago
it will return false
JJ
JJOP2y ago
yes you are right haha
TheRanger
TheRanger2y ago
we suggested you to use Contains like 3 times
JJ
JJOP2y ago
oh I see I resolved it thanks! I resolved it thanks!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server