Change case of 7th character
-
I’d like to change the case of the 7th character of a string beginning with T5A0.
My xml files using this string as a reference and case mismatch is causing an issue.
Here are more specifics:Some work packages (xml files) are coded with lower case id’s in the 7th character field. Example code:
wpno="T5A013e"
Some 7th characters are coded with upper case:
wpid="T5A014A"
Some only have 6 characters:
wpno="T5A014"
In all cases, the string begins with T5A0 and ends with a quotation mark.
If there is a 7th character, I’d like to change it to lower case.
So, in the examples above,
T5A013e would remain as is.
T5A014A would change to T5A014a.
T5A014 remains as is.Here is my system info:
Notepad++ v8.1.5 (64-bit)
Build time : Sep 26 2021 - 15:23:23
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Pro for Workstations (64-bit)
OS Version : 2009
OS Build : 19042.1237
Current ANSI codepage : 1252
Plugins : ComparePlugin.dll mimeTools.dll NppConverter.dll NppExport.dll XMLTools.dllThanks in advance!
-
Thank you for sharing examples of data that should and should not be changed; that helps define a correct expression.
Use regular expressions.
FIND =(?-i)(T5A0..)(\u)
REPLACE =$1\L$2
SEARCH MODE = regular expressionThe find expression puts it it case-sensitive match, then looks for
T5A0
followed by two characters and puts those 6 characters into group#1, then it looks for a single uppercase character and puts it in group #2. The replacement expression puts back the 6 characters using group#1, then changes whatever comes next to lowercase using the\L
replacement escape, then puts back group#2 – since group#2 is"whatever comes next", it is made uppercase.Note that sequences that have
T5A0
followed by only two characters, orT5A0
then two characters then a lowercase will not match, and so won’t be replaced (and thus stay the same, as you requested)For learning more on regular expressions, check out our regex resources listed in the FAQ section.
-
@PeterJones said in Change case of 7th character:
$1\L$2
Thank you Peter!
That worked perfectly!
Appreciate it very much.