Click here to Skip to main content
15,666,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi there, I have file name which is called for example
and I want to remove until F, but I want to do this by character for example

fileName.removeBySpesificCharacter("F"); and I want to get back the result like this


The reason why I am deleting by spesific character because of my OID generate randomly.

What I have tried:

I have tried to find any solution but I couldn't.
Updated 21-Jul-22 23:06pm

[fixed, thanks to zemiak123]
You may use the String.indexOf[^] method. Try
static String untilChar(String strIn, int chr)
  int index = strIn.indexOf(chr);
  if ( index != -1 )
    strIn = strIn.substring(index);
  return strIn;

public static void main( String arg[] )
  String s = "4jl5kljza8100pFileName.pdf";
  System.out.println( untilChar(s, 'F'));

Share this answer
[no name] 22-Jul-22 3:50am    
> "I want to remove until F"
so correct is
  //strIn = strIn.substring( 0, index );
    strIn = strIn.substring( index );
but what if generated ID contains F ?
CPallini 22-Jul-22 3:55am    
You are right, thank you for pointing it out.
Patrice T 22-Jul-22 5:07am    
CPallini 22-Jul-22 5:09am    
Thank you.
Is there any method in java cut string value by spesific value?

Did you tried to use RegEx ?
This RegEx "[A-Z].+" match from first uppercase til the end.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre -[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900