Python Forum
Take particular symbol from textbox help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Take particular symbol from textbox help (/thread-25836.html)



Take particular symbol from textbox help - samuelbachorik - Apr-13-2020

Hello dear users, i have trouble with getting particular symbol from my textbox. For example i have in my textbox -> 5 + 5m

And i want to ask you is it possible to make variable always from number before m ? In this case it would be value = 5. Is it possible to say in python take number before m and make it variable ?

We can image in it also in input. If user put in input 5 + 5m. How can i take from this text only that 5 before m ?

THANK YOU A LOT.


RE: Take particular symbol from textbox help - deanhystad - Apr-13-2020

I don't understand your question. Is the question about how to get a string from a textbox or is it about how do you process a string to get a number?

If the latter, what is the string, "5 + 5m" or "-> 5 + 5m"?

What is special about "m"? Is this a special marker that you are looking for (always get the number just before "m") or does it just represent any non-numeric character (ignore things that are not numbers)? More information about the problem you are trying to solve would be helpful.


RE: Take particular symbol from textbox help - TomToad - Apr-13-2020

Do you only want a single digit before m? Entire number before m? Entire expression before m? Is there always a space between the operator and number? Is there always no space between the number and m? Is there more than one number/symbol pair? Depending on the answer to those questions, different solutions can be used.

For simple cases, you can use find and rfind to get the span of the number and then strip it by slicing. More complex cases might use regular expressions.


RE: Take particular symbol from textbox help - steve_shambles - Apr-14-2020

If I understand correctly, you want to capture the integer that
appears before the "m"?
which presumably will be different on occasion.

If you can get the text you want to look at into a
string it should be fairly easy:

Example:
some_text = "5 + 5m"
num_b4_m = (some_text[:2])
print(num_b4_m)
Will return the number 5
via the num_b4_m variable.