Python Forum
Take particular symbol from textbox help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Take particular symbol from textbox help
#1
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.
Reply
#2
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.
Reply
#3
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.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decryption not working if key has same symbol like text Paragoon2 0 312 Nov-11-2023, 09:32 PM
Last Post: Paragoon2
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,324 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  ImportError: /home/pybind11_example.cpython-37m-x86_64-linux-gnu.so: undefined symbol chaitra 2 5,098 Feb-03-2021, 05:14 AM
Last Post: chaitra
  Hide symbol or characters in regular expression Gateux 0 2,264 Mar-21-2020, 10:25 AM
Last Post: Gateux
  loop through range until reach size and exclude specific symbol pino88 3 2,370 Sep-23-2019, 02:32 AM
Last Post: perfringo
  add a textbox in an image Akhou 17 10,947 May-23-2018, 09:07 AM
Last Post: Akhou
  "³" math cube symbol encoding Ragnar 5 9,547 Mar-09-2018, 04:23 PM
Last Post: Gribouillis
  Print func textbox instead of shell zykbee 1 5,250 Dec-06-2017, 08:22 PM
Last Post: nilamo
  matplotlib textbox kiyoshi7 3 6,017 Oct-21-2017, 10:57 PM
Last Post: kiyoshi7
  help with showing wifi symbol when connected bowen73 8 6,245 Aug-03-2017, 01:57 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020