How to insert letter between two letter in a text input? - python-3.x

I want to make a function in a module i have made, to insert letter’ s before some specific letter ''vowel in fac'' in a text input. The text can be everything written by everybody. Can be letter, number, symbol. But for this function it will be only for letter’s.
Fist fonction.
For exemple, in the input field : (John get in2 the train.)
I want when i press on the button of my function,
that the result show : (javohn gavet avin2 thave travain)
Second function.
And make the same in the reverses procedure ,
input field :(javohn gavet avin2 thave travain)
and the after i press the button : John get in2 the train.
I have made something whit a dictionnaire in another programme and change all the letter’s in a text by another one and do the reverse, and work well. But this don’t work for what i want do to whit insertion of letter in a text. Or i miss something….I’m new in programming, but i love this, and a lot to learn. Im a self learning….. Thank for your help or ‘’Q’’ in the good direction.
I put a picture of my code.
[the code1
this one work well for another application, but not here for what i want to do.

I recommend regex for this. Specifically the sub() function. If you wanted to replace every 'e' and 'i' with 've' and 'vi', you could do this:
re.sub(r"[ei]",lambda x:"v"+x.group(0),my_text)
where my_text is a variable containing the text input.
For your second function, it would be something like:
re.sub(r"ve|vi",lambda x:x.group(0)[1],my_text)
The way this sub() function works is that it finds every match of the regex pattern, then applies a function to get the replacement string. In the first case it adds a 'v' in front. In the second case it takes the second letter.

Related

How to make an excel (365) function that recognizes different words in the same cell and changes them individually

What im working with
I have a list of product names, but unfortunately they are written in uppercase I now want to make only the first letter uppercase and the rest lowercase but I also want all words with 3 or less symbols to stay uppercase
im trying if functions but nothing is really working
i use the german excel version but i would be happy if someone has any idea on how to do it im trying different functions for hours but nothing is working
=IF(LENGTH(C6)<=3,UPPER(C6),UPPER(LEFT(C6,1))&LOWER(RIGHT(C6,LENGTH(C6)-1)))
but its a #NAME error excel does not recognize the first and the last bracket
This is hard! Let me explain:
I do believe there are German words in the mix that are below 4 characters in length that you should exclude. My German isn't great but there would probably be a huge deal of words below 4 characters;
There seems to be substrings that are 3+ characters in length but should probably stay uppercase, e.g. '550E/ER';
There seem to be quite a bunch of characters that could be used as delimiters to split the input into 'words'. It's hard to catch any of them without a full list;
Possible other reasons;
With the above in mind I think it's safe to say that we can try to accomplish something that you want as best as we can. Therefor I'd suggest
To split on multiple characters;
Exclude certain words from being uppercase when length < 3;
Include certain words to be uppercase when length > 3 and digits are present;
Assume 1st character could be made uppercase in any input;
For example:
Formula in B1:
=MAP(A1:A5,LAMBDA(v,LET(x,TEXTSPLIT(v,{"-","/"," ","."},,1),y,TEXTSPLIT(v,x,,1),z,TEXTJOIN(y,,MAP(x,LAMBDA(w,IF(SUM(--(w={"zu","ein","für","aus"})),LOWER(w),IF((LEN(w)<4)+SUM(IFERROR(FIND(SEQUENCE(10,,0),w),)),UPPER(w),LOWER(w)))))),UPPER(LEFT(z))&MID(z,2,LEN(v)))))
You can see how difficult it is to capture each and every possibility;
The minute you exclude a few words, another will pop-up (the 'x' between numbers for example. Which should stay upper/lower-case depending on the context it is found in);
The second you include words containing digits, you notice that some should be excluded ('00SICHERUNGS....');
If the 1st character would be a digit, the whole above solution would not change 1st alpha-char in upper;
Maybe some characters shouldn't be used as delimiters based on context? Think about hypenated words;
Possible other reasons.
Point is, this is not just hard, it's extremely hard if not impossible to do on the type of data you are currently working with! Even if one is proficient with writing a regular expression (chuck in all (non-available to Excel) tokens, quantifiers and methods if you like), I'd doubt all edge-case could be covered.
Because you are dealing with any number of words in a cell you'll need to get crafty with this one. Thankfully there is TEXTSPLIT() and TEXTJOIN() that can make short work of splitting the text into words, where we can then test the length, change the capitalization, and then join them back together all in one formula:
=TEXTJOIN(" ", TRUE, IF(LEN(TEXTSPLIT(C6," "))<=3,UPPER(TEXTSPLIT(C6," ")),PROPER(TEXTSPLIT(C6," "))))
Also used PROPER() formula as well, which only capitalizes the first character of a word.

Looking to remove a space in one of the results while performing multiple mid searches on a column

I am trying to embed a SUBSTITUTE in my function, but I am not sure where to incorporate it. I am trying to extract just the text "Scrumactiviteiten" but in the source data sometimes a space will be in there. A sample:
Column A
1 Team xxxx 2018-17 Scrumactiviteiten 123 and then something
2 Team xxxx 2018-17 Scrum activiteiten 123 and then something
Column B (My formula)
1 Scrumactiviteiten
2 Scrum activiteiten
The function I used to extract it (ignore the "Balans" search please):
=IFERROR(IFERROR(IFERROR(MID(A1;SEARCH("Scrum activiteiten";A1;1);18);
MID(A1;SEARCH("Scrumactiviteiten";A1;1);17));MID(A1;SEARCH("Balans";A1;1);10));" ")
This works fine, but to remove the space I tried to embed a SUBSTITUTE where I use the mid search result as the old text and provide "Scrumactiviteiten" as the new text:
=IFERROR(IFERROR(IFERROR(SUBSTITUTE(A24;((MID(A24;SEARCH("Scrum activiteiten";A24;1);18)));"Scrumactiviteiten");MID(A24;SEARCH("Scrumactiviteiten";A24;1);17));MID(A24;SEARCH("Balans";A24;1);10));" ")
The result however is a copy of the full string. I also tried putting the substitute before the search but that would not work either. I am pretty new to Excel formula's and I think I messed up the order or just plain don't understand how I embed a SUBSTITUTE in the formula I created. Some explanation would be much appreciated on what I'm doing wrong! Thank you in advance,
Mark
The problem is you are not providing the correct arguments to the function, try this formula:
=IFERROR(IFERROR(IFERROR(SUBSTITUTE(((MID(A24;SEARCH("Scrum activiteiten";A24;1);18)));" ";"");MID(A24;SEARCH("Scrumactiviteiten";A24;1);17));MID(A24;SEARCH("Balans";A24;1);10));" ")
To use SUBSTITUTE you first provide the string in which you want to replace something, the next two arguments are the string you want replaced and the string you want to replace it with. So for example =SUBSTITUTE("Scrum activiteiten";" ";"") returns Scrumactiviteiten as the space " " is replaced with an empty string "".

Is there a way to use the Find and Replace function in Excel to replace the first and last entry in a string of text?

I have a sequence of a letters, in my case part of a gene. I want to change the first and the last letter in this string of text, but keep the internal characters the same.
For example, if I have the the sequence:
ATCGAATCCATGACG
And I want to change the first letter, in this case A to the word START and change the last letter, G, to STOP all while keeping the internal A's and G's the same. Is this possible to do with the Find and Replace function, or will I have to write a script?
It is easy to do when I have a handful of sequences, I do it by hand. When I get into the hundreds, it can be very difficult.
Thank you.
The function LEN(text) returns the number of characters within a string of letters. MID(text, start, num_chars) returns the middle section of a string. CONCATENATE(text1, text2, ...) pieces together different strings. We can use these in combination to get what you want:
=CONCATENATE("START", MID(A1,2,LEN(A1)-2), "STOP")
You could use replace, and focus on the left and right side independently, then combine, or you can use left/right to add string of text to the available string minus a character, like:
="START"&LEFT(RIGHT(A1,LEN(A1)-1),LEN(A1)-2)&"STOP"
I used left/right, but mid would also work
just another option:
=REPLACE(REPLACE(A1,LEN(A1),1,"STOP"),1,1,"START")

Search function to send all variations of the text uppercase an lowercase

I have a function that uses an api to pull information based on the text given in the request.
The problem is that the text has to match the item exactly. Such as the item is named "Peach and Apple" and if you type "peach and apple" it will not return. You have to type "Peach and Apple" in order to properly request the item.
Is there a way I can send every variation of "Peach and Apple" (just incase is was something weird like "Peach and Le'Apple") with every variation of an uppercase letter?
I could make it uppercase every letter at the start of the string which is easy and would work with a lot of requests. Then I could uppercase every letter after a space which with the previous change would handle ALMOST every search.
The problem is I cannot make it uppercase every letter after a ' for this example(reason):
"Peach and Le'Apple" would work but "Peach and Apple's Leaf" would not work since the s is not uppercase. Thus is there a way to properly search for this?
Thanks for your time!!!
So I figured a way around it. The problem was that the items I was searching for had to be in the exact form. I was the one that saved those items from the api. So when I save them now I have 2 separate columns. One that saves the name with uppercase that will be what is shown on screen and another that saves the same name only purely converted to lowercase with toLowerCase(). This lets me search for the items and still keep the nice uppercase name without having to do some nasty logic I dont want to do.

VB Split Multiple Spaces and Remove Words

I'm making a little program so I can get a better view of donations for a game.
What I want the program to do is split the text from textbox1.text into multiple textboxes.
Example: I want to split this text "20:12 01-04-2014 Ramon Geen $4.500.000.000".
So I want the name "Ramon" in a textbox called Name1 and I want the money in a textbox called Donation.
I already know how to remove the date from the text but I don't know how to remove the comment which can be different than Geen and I also don't know how to split the name and donation into separate textboxes. Can anyone tell me how to go about doing this?
Thanks in advance!
If the string is going to be completely variable then you may have some issues.
However, you know the following.
The right most text is always the money, so you can split the string on space and then put it into an array. Then the last element in the array will be the money. Also, the first portion will be the date. The second item in the array will be the name and everything else will be the comment.
I'm not going to code it all out for you, but if you have any questions just post the code and ill take a look.

Resources