Excel Len function - excel

I have a probleem in excel and i didnt figure it out how to do it right. anyway i'll give you an example to explain it correctly.
Name Surname Code
Martin Kara Maar4 (=> First two letters from Martin and 2nd en 3rd letters from surname and code is 4 and that's the lenght of the surname.
the probleem is i wanted to see the Maar4 as Maar04 not as Maar4.
I have already checked the formatcell but still didnt find it.
this is the code i wrote it:
=UPPER(LEFT(A2;2)& MID(B2;2;2)&LEN(B2))
thank you
edit: problem is solved. you guys are amazing. thank you

I'm not sure why you're using UPPER() if you expect Maar04. If you do want to get Marr04, you would use:
=LEFT(A2;2)&MID(B2;2;2)&TEXT(LEN(B2);"00")
If you want to get MAAR04, then you'd use the uppercase:
=UPPER(LEFT(A2;2)&MID(B2;2;2)&TEXT(LEN(B2);"00"))

Try using TEXT function to force 2 digits
=UPPER(LEFT(A2;2)& MID(B2;2;2))&TEXT(LEN(B2);"00")

If you're quite sure the length will never go above 99 you can try this hack:
=UPPER(LEFT(A2;2)& MID(B2;2;2)&RIGHT(LEN(B2)+100,2))

Need to use REPT() to achieve this.
See: http://office.microsoft.com/en-us/excel-help/rept-HP005209236.aspx
Your formula MIGHT look somehing like this;
=UPPER(LEFT(A2;2)& MID(B2;2;2)&REPT(0,LEN(B2)))

Related

How to simplify 4 nested IF functions in EXCEL

This might be a simple fix I'm unsure. I have the following formula which I would like to be able to drag up and down =IF(C311>B311,IF(C310>B310,IF(B309>C309,IF(C312>B312,2,1),0),0),0)
I'm guessing AND can be implemented in some way but I'm not sure. The logic behind my goal is if C311>B311 AND C310>B310 AND B309>C309 then check to see if C312>B312 if it is then put a 2 else put a 1. Perhaps there is another solution as well I'm not thinking of.
Try this: =IF(AND(C311>B311,C310>B310,B309>C309),IF(C312>B312,2,1),"")
Last argument I left it as "" but replace it to whatever you need.
Just another approach-
=IF((C311>B311)*(C310>B310)*(B309>C309),IF(C312>B312,2,1),"")

How do I split individual character within a list that is within a list?

I am working on a project in Python, and I stumbled across this hindrance.
I have something like this:
[['abcde'],['bcdef']]
How do I make it such that it gives me this? :
[['a','b','c','d','e'],['b','c','d','e','f']]
Thank you for helping
It would be better if you start reading docs
[list(string) for string in given_list]
or otherwise
list(map(list,given_list))

Finding a character inside a string in Excel

I want to remove all the characters from a string expect whatever character is between a certain set of characters. So for example I have the input of Grade:2/2014-2015 and I want the output of just the grade, 2.
I'm thinking that I need to use the FIND function to grab whatever is between the : and the / , this also needs to work with double characters such 10 however I believe that it would work so long as the defining values with the FIND function are correct.
Unfortunately I am totally lost on this when using the FIND function however if there is another function that would work better I could probably figure it out myself if I knew what function.
It's not particularly elegant but =MID(A1,FIND(":",A1)+1,FIND("/",A1) - FIND(":",A1) - 1) would work.
MID takes start and length,FIND returns the index of a given character.
Edit:
As pointed out, "Grade:" is fixed length so the following would work just as well:
=MID(A1,7,FIND("/",A1) - 7)
You could use LEFT() to remove "Grade:"
And then use and then use LEFTB() to remove the year.
Look at this link here. This is the way I would go about it.
=SUBSTITUTE(SUBSTITUTE(C4, "Grade:", ""), "/2014-2015", "")
where C4 is the name of your cell.

With data.table, return between certain characters into a new column

I have a feeling this might be a simple question, but I've searched through SO for a bit now and found many interesting related Q/A, I'm still stumped.
Here's what I need to learn (in honesty, I'm playing with the kaggle Titanic dataset, but I want to use data.table)...
Let's say you have the following data.table:
dt <- data.table(name=c("Johnston, Mr. Bob", "Stone, Mrs. Mary", "Hasberg, Mr. Jason"))
I want my output to be JUST the titles "Mr.", "Mrs.", and "Mr." -- heck we can leave out the period as well.
I've been playing around (all night) and discovered that using regular expressions might hold the answer, but I've only been able to get that to work on a single string, not with the whole data.table.
For example,
substr(dt$name[1], gregexpr(",.", dt$name[1]), gregexpr("[.]", dt$name[1]))
Returns:
[1] ", Mr."
Which is cool, and I can do some further processing to get rid of the ", " and ".", but, the optimist(/optimizer) in me feels that that's ugly, gross, and inefficent.
Besides, even if I wanted to settle on that, (it pains me to admit) I don't know how to apply that into the J of data.table....
So, how do I add a column to dt called "Title", that contains:
[1] "Mr"
[2] "Mrs"
[3] "Mr"
I firmly believe that if I'm able to use regular expressions to select and extract data within a data.table that I will probably use this 100x a day. So thank you in advance for helping me figure out this pivotal technique.
PS. I'm an excel refugee, in excel I would just do this:
=mid(data, find(", ", data), find(".", data))
Umm.. I may have figured it out:
dt[, Title:=sub(".*?, (.*?)[.].*", "\\1", name)]
But I'm going to leave this here in case anyone else needs help, or perhaps there's an even better way of doing this!
You can use the stringr package
library(stringr)
str_extract(dt$name, "M.+\\.")
[1] "Mr." "Mrs." "Mr."
Different variations on the regular expression will let you extract other titles, like Dr., Master, or Reverend which may also be of interest to you.
To get all characters between "," and "." (inclusive) you can use
str_extract(dt$name, ",.+\\.")
and then remove the first and last characters of the result with str_sub (also from stringr package).
But as I think about it more, I might use grepl to create indicator variables for all the different titles that are in the Titanic dataset. For example
dr_ind <- grepl("Dr|Doctor", dt$name)
titled_ind <- grepl("Count|Countess|Baron", dt$name)
etc.

How to find text between two markers

I've got the below string and want to find and then join together everything in between '^[#n' and '$,s)'. these two markers may occur more than one time in our string. thanks in advance for your help.
string="O8d:^[#nI just $,s):<#Rh9f^[#n don't know $,s)>jwU*/#'^[#nhow to write this code $,s){<3f9(f3#"
for example,here the output is:
I just don't know how to write this code
You can use re.findall with a lazy quantifier:
print("".join(re.findall(r'\^\[#n(.*?)\$,s\)', string)))

Resources