function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ard_17ard_17 

How to find and replace string between two characters in formula?

I have a text field that could contain text like:
"Please consult the related form [15dr4] for details"

But I'm trying to create a separate formula field that will hide the "15dr4" or whatever text is between the two brackets, but display the rest of the text.l Is this possible?

I appreciate any help. Thanks!
Shri RajShri Raj

Yes, it is possible to find and replace a string between two characters in a formula field. One way to accomplish this is to use the MID and FIND functions in combination with one another.

=LEFT(A1,FIND("[",A1)-1) & RIGHT(A1,LEN(A1)-FIND("]",A1))


This formula uses the LEFT function to return the portion of the string before the first [, and the RIGHT function to return the portion of the string after the last ]. The FIND function is used to locate the positions of the brackets. This formula can be used to replace the text between the two brackets with an empty string, effectively hiding it.
Shivam SolankiShivam Solanki
Here is the syntax in different programming languages:

In Python

def replace_between_chars(string, char1, char2, replace_with):
    start = string.index(char1)
    end = string.index(char2, start)
    return string[:start + 1] + replace_with + string[end:]

In Java:

public static String replaceBetween(String str, String replace, char start, char end) {
    int startIndex = str.indexOf(start) + 1;
    int endIndex = str.indexOf(end, startIndex);
    return str.substring(0, startIndex) + replace + str.substring(endIndex);
}

In JavaScript:

function replaceBetween(string, char1, char2, replaceWith) {
    let start = string.indexOf(char1) + 1;
    let end = string.indexOf(char2, start);
    return string.substring(0, start) + replaceWith + string.substring(end);
}

In PHP:

function replace_between_chars($string, $char1, $char2, $replace_with) {
    $start = strpos($string, $char1) + 1;
    $end = strpos($string, $char2, $start);
    return substr_replace($string, $replace_with, $start, $end - $start);
}


https://pickon.in/bolly4u-movies-bollywood-hollywood/
https://pickon.in/soap2day-to/
https://pickon.in/vegamovies/
https://pickon.in/katmoviehd/
https://pickon.in/that-90s-show-soap2day-review/
Arun Kumar 1141Arun Kumar 1141
Hi ard_17,

Yes, it's possible to create a formula field that will hide the text between the brackets and display the rest of the text. Here's an example formula that you could use:


LEFT(Text_Field__c, FIND("[", Text_Field__c) - 1) & RIGHT(Text_Field__c, LEN(Text_Field__c) - FIND("]", Text_Field__c))

Replace "Text_Field__c" with the API name of your text field.

This formula uses the LEFT and RIGHT functions to extract the text before and after the brackets. The FIND function is used to find the positions of the opening and closing brackets, and the LEN function is used to calculate the length of the string.

This formula assumes that the text field always contains the brackets with text in between. If there's a possibility that the brackets may not be present, you can modify the formula to include a check for that, for example:

IF(
  FIND("[", Text_Field__c) > 0 && FIND("]", Text_Field__c) > 0,
  LEFT(Text_Field__c, FIND("[", Text_Field__c) - 1) & RIGHT(Text_Field__c, LEN(Text_Field__c) - FIND("]", Text_Field__c)),
  Text_Field__c
)
This formula checks if both brackets are present before extracting the text. If the brackets are not present, it simply returns the original text.

Please mark it as best answer if it will help you.
Thanks
pomij maryapomij marya
It's great to be here with everyone, I have a lot of knowledge from what you share cashewsinfo
toby bishoptoby bishop
Yes, it is possible to create a formula field that hides the text between brackets and displays the rest of the text. You can achieve this using string manipulation functions in the programming language or platform you are working with.

Here's an example formula that you can adapt to your specific programming language or platform:

```python
text = "Please consult the related form [15dr4] for details"
start_index = text.find("[")  # Find the index of the opening bracket
end_index = text.find("]")  # Find the index of the closing bracket

if start_index != -1 and end_index != -1:  # If both brackets are present
    hidden_text = text[start_index+1:end_index]  # Extract the text between brackets
    visible_text = text[:start_index] + text[end_index+1:]  # Concatenate the text before and after the brackets
else:
    hidden_text = ""  # If the brackets are not found, there is no hidden text
    visible_text = text  # The entire text is visible

print("Hidden Text:", hidden_text)
print("Visible Text:", visible_text)
```

In this example, the `find()` function is used to locate the positions of the opening and closing brackets. If both brackets are found, the text between them is extracted and stored in the `hidden_text` variable. The visible text is obtained by concatenating the text before the opening bracket (`text[:start_index]`) with the text after the closing bracket (`text[end_index+1:]`).

You can adapt this logic to your specific programming language or platform to achieve the desired result in your application or system.
theapk (https://theapkasphalt.com)
Christine G. Williams WilliamsChristine G. Williams Williams
Hello, 
There are many ways to find and replace strings between two characters. like this:
import re

formula = "SUM(A1:A10)"
replacement = "B1:B10"

new_formula = re.sub(r'\(.*?\)', f'({replacement})', formula)
print(new_formula)  # Output: SUM(B1:B10)

In this example, it is in a python language. it's simply to find in pythonhttps://www.myfedloan.us/
Ahmad Bilal 10Ahmad Bilal 10
Hi Guys!
Let's check ADAM WhatsApp (https://apksforwamods.com/adam-whatsapp-apk/) which performance speaks for itself.