How to substring before nth occurence of a separator?

How to substring before nth occurence of a separator?

By : Lorna
Date : November 25 2020, 04:01 AM
With these it helps Use StringUtils.ordinalIndexOf() from Apache
Finds the n-th index within a String, handling null. This method uses String.indexOf(String).
code :
public static int ordinalIndexOf(String str, String substr, int n) {
    int pos = str.indexOf(substr);
    while (--n > 0 && pos != -1)
        pos = str.indexOf(substr, pos + 1);
    return pos;

Share : facebook icon twitter icon
Get substring between first and nth occurence of pattern

Get substring between first and nth occurence of pattern

By : Troycloyd Cloyd
Date : March 29 2020, 07:55 AM
I hope this helps you . Here's one way using sed. This will select the substring between the 1st and nth occurrence. The number present is in the form n - 1:
code :
sed 's/^[^_]\+_\+\(\(_*[^_]\+\)\{3\}\).*/\1/'
sed -r 's/^[^_]+_+((_*[^_]+){3}).*/\1/'
echo "AAA_BBBB__CCC__GGGG___fffffffffffffff_hhhh" | sed -r 's/^[^_]+_+((_*[^_]+){3}).*/\1/'
sed -r 's/^([^_]+_+){4}((_*[^_]+){1}).*/\2/'
how to get the second (third...) occurence of a substring in xslt?

how to get the second (third...) occurence of a substring in xslt?

By : Sumana
Date : March 29 2020, 07:55 AM
around this issue With xslt-1.0: This could be done by a combination of substring-after and substring-before.
code :
<xsl:value-of select="substring-before(
                substring-after ($vari, , '=')
               , '=')"/>                    
<xsl:value-of select="substring-before(
                 substring-after ( substring-after ($vari,  '='),  '=')
                 , '=')"/>                  
How to extract substring with sed but first occurence only?

How to extract substring with sed but first occurence only?

By : Javier Ciangarotti
Date : March 29 2020, 07:55 AM
Does that help Using sed -n "s/.*\(\/.*\/\).*/\1/p on /string1/string2 produces string1, as expected. , This might work for you (GNU sed):
code :
sed -n 's/[^\/]*\(\/[^\/]*\/\).*/\1/p' file
To print only the first occurence of a substring in c

To print only the first occurence of a substring in c

By : Ostap
Date : March 29 2020, 07:55 AM
wish of those help I am new to C. I have a code like this , This should work.
code :
 #include <stdio.h>
 #include <string.h>

 int i=0;
 int main()
    char text[] = "..... $it is beautiful : $yes you are correct....";
    char* sub = "$";
    char* ret = strstr(text,sub);
    char *out = malloc(strlen(text)+1); //To make the solution generic

    if (ret!=NULL )
         sscanf(ret, "$%[^$^:]", out);
         printf("the statement is : [%s] \n",out );

Substring of a specific occurence

Substring of a specific occurence

By : Wenglish
Date : March 29 2020, 07:55 AM
hop of those help? I have a column as varchar2 datatype, the data in it is in format: , One way is to use REGEXP_SUBSTR:
code :
SELECT REGEXP_SUBSTR(column_name,'^[^.]*') FROM table
SELECT SUBSTR(column_name, 1, INSTR(column_name,'.') - 1) FROM table
Related Posts Related Posts :
  • How do I make this image larger?
  • Run icCube with JDK 10
  • Expression with Math.random() always returns the same value
  • Getting the Set with the most elements nested in a HashMap using Java Streams
  • XmlSlurper to parse XML and get value of inside elements using Groovy
  • Extracting data from HTML and formatting the output
  • SOLR documentCache JMX metrics clarification
  • Limiting Wildfly 14 Two-Way SSL to specific clients
  • How do I get Min and max values to only print when "year" is entered?
  • Hashmap can't loop - getKey() method not found - Using Java 8
  • Android Studio - Create an EditText with a click of a button
  • Mockito Test not invoking verify() method
  • Wrap method implementations of Java interfaces
  • Remediating dynamic SQL into prepared statements
  • Where do X and Y start at in swing windows
  • java code with files work from eclipse but dont work from cmd
  • Return page object from JPA query
  • I can't figure out why this code in my APCS multiple choice book returns 19
  • How to save data between methods
  • I'm trying to install Apache Gobblin. How can I install it using Gradle?
  • Spring Data Sorting Array or Set into Pageable
  • Question about the Java documentation and its implementation
  • How to make a JButton that when pressed it does a new action
  • Java hibernate No validator could be found for boolean
  • Making a POJO Thread Safe
  • Save the data of a text file in a arraylist
  • Sort a List<String[]> by indices using Comparator
  • Overloading in Java for user input?
  • Unable to format timestamp as YYYY-MM-DD HH:mm:ss in java
  • Access SQLite Helper From Adapter
  • How to stream a csv file with header to a HashMap<String, Double> in Java?
  • can't get go daddy ssl certificate to work with spring boot
  • ResourceBundle can't find BaseName gradle project java
  • Java; Jackson; Parsing the array of array json string
  • Java - map key lookup ignoring case
  • Jackson deserialize map null values to empty string
  • Anyone knows why setCount() is not working in twitter4j?
  • Object Visibility in a Multi-threaded Program in Java
  • Can't store and load an arraylist in an object file
  • convert a string number starts with `00` to `+` in java
  • Java - avoiding NonSuchElementException using ConcurrentLinkedDeque
  • Converting Immutable to mutable list Java
  • Getting nosuchmethod exception
  • How to get MQTT subscriptions
  • Android Google Sign in Exceptions
  • JavaFX - method that waits for user input
  • Replacing values for a particular key in treemap changes values for every key
  • This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter th
  • Kafka: consume all messages on demand
  • Notify what text was changed in textview
  • Tinkerpop/Gremlin: select vertices together with outgoing edge count
  • transform a list of objects into a list of integers that pass a check
  • Why this java code is showing strange behavior?
  • Maven Project classes not compiling
  • Edit image to make text more clear opencv
  • Android Spinner nullpointer
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org