SUBSTITUTE then replaces only the second dot with "*" resulting in the text "*com".1 Daily Challenge #1 - String Peeler 2 Daily Challenge #2 - String Diamond. The result (2) is the number of dots in the text, which is provided to SUBSTITUTE as instance_num: SUBSTITUTE(B5,".","*",2) The above expression evaluates like this: =LEN(B5)-LEN(SUBSTITUTE(B5,".","")) Here, we calculate the total number of characters in the domain with LEN, then we subtract the total number of characters with all dots removed with the SUBSTITUTE function. Instead, we need to take a manual approach based on the LEN function: LEN(B5)-LEN(SUBSTITUTE(B5,".","")) Figuring out which instance to replace is the hardest part of this problem because we have no direct way to count how many dots are in a text string. if 2 is provided, SUBSTITUTE will replace the second instance). However, if an instance_num is provided, SUBSTITUTE will only replace that particular instance of old_text (i.e. If no value is supplied for instance_num, SUBSTITUTE will replace all instances of old_text with new_text. The trick is that the SUBSTITUTE function has an optional fourth argument that specifies which "instance" of the old_text should be replaced. This snippet does the actual replacement of the last dot with an asterisk (*). How does the formula know to replace only the last dot? This is the clever and complicated part. Once the position is known, the RIGHT function is used to extract the TLD. All of the other functions in this formula just do one thing: they figure out how many characters (n) need to be extracted: =RIGHT(B5,n) // n = ?Īt a high level, the formula replaces the last dot "." in the domain with an asterisk (*) and then uses the FIND function to locate the position of the asterisk. At the core, the formula uses the RIGHT function to extract characters starting from the right. However, it operates in a series of small steps. This is an intimidating formula, complicated by the fact that the text functions in older versions of Excel are quite limited. However, you can still extract the top-level domain (TLD)with a more complicated formula based on several text functions including RIGHT, FIND, LEN, and SUBSTITUTE: =RIGHT(B5,LEN(B5)-FIND("*",SUBSTITUTE(B5,".","*",LEN(B5)-LEN(SUBSTITUTE(B5,".",""))))) Older versions of Excel do not provide the TEXTAFTER function. As the formula is copied down, the other top-level domains are returned.įor more on TEXTAFTER, see How to use the TEXTAFTER function. With the text "" in cell B5, TEXTAFTER splits the string at the last "." and returns "com", which is the top-level domain. instance_num - given as -1 for the last instance.The TEXTAFTER function is configured with the following inputs: In the worksheet shown, the formula in cell D5 is: =TEXTAFTER(B5,".",-1) However, for this problem, we only need to provide the first three arguments: =TEXTAFTER(text,delimiter,instance_num) The generic syntax for TEXTAFTER supports many options: =TEXTAFTER(text,delimiter, ) The TEXTAFTER function returns the text that occurs after a given delimiter. In this example, the goal is to extract the top-level domain (TLD) from a list of domains. A top-level domain is the last segment of text in a domain name, for example, ".com", ".net", or ".net". In the current version of Excel, the TEXTAFTER function is a simple way to solve this problem. In an older version of Excel, you can use a more complicated formula based on several text functions including RIGHT, FIND, LEN, and SUBSTITUTE.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |