❔ [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
FindAll error
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 propertyoh yes thanks !
can u give an example on what ur trying to find?
you want to check if for example
es
is in Test
?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));
}
}
what do u expect FindAll returns?
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"
ud probably off better using string's Contains method instead
If you want to check if a particular substring is in a string you can use the
Contains
function.is there return string at c#? if it is not, I would return index number if same
i dont see why you need to return the string, just use the string from the textbox who's value is
as
this is also having problem
what problem? i cant read the error message
Oh, Im doing implement toyproject this
Im making Sticky Notes like picture
are you looking for the index "as" starts from?
well it tells you
No overload for method 'FindIndex' takes 1 arguments
Im looking for comparing between string
string's Contains method should work for you
TheRanger#3357
REPL Result: Success
Result: bool
Compile: 486.987ms | Execution: 27.185ms | React with ❌ to remove this embed.
i assume u wanna filter your sticky notes to show notes who contains your input, right?
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
nope that wont work
I found it ,
TheRanger#3357
REPL Result: Success
Result: bool
Compile: 510.925ms | Execution: 26.215ms | React with ❌ to remove this embed.
it will return false
yes you are right haha
we suggested you to use
Contains
like 3 timesoh I see
I resolved it thanks!
I resolved it thanks!
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.