Trim text length in word Field codes - ms-word

Working with the automatic word Field codes a fun function is getting the File name.
The following correctly displays the file name in Upper case.
FILENAME \* Upper
Is there a way to also trim the length off the filename?
Example:
MyFileWithItsName.docx => I would like to only keep => MyFile
Thank you.

Related

Output filename to VSCode replace string

Say I have a search I want to do across my entire project: callToMyFunction()
And I would like to replace it with:
callToMyFunction();
console.log("calling function from ${filename}");
Is there a way (or an extension) that could do the ${filename} (or whatever) where the filename of the file where the replacement string is being applied gets written in?
If a search match was found in the file index.js the replacement would be:
callToMyFunction();
console.log("calling function from index.js");
[BONUS if there is a way to also get line number, but I'd be more than satisfied with just the filename 😁]

How to remove double Quotes In DataStage using a transformer stage?

We receiving Input data like below
“VENKATA,KRISHNA”
I want output like below
VENKATA,KRISHNA
Can anyone help me with this
Check out the Ereplace function - it allows to replace certain characters so you could rplace " with '' (empty string).
An alternative is TRIM - you can specify which character the command should trim and also if All occurrences or Both (from both sides of the string) plus more.

how to remove # character from national data type in cobol

i am facing issue while converting unicode data into national characters.
When i convert the Unicode data into national using national-of function, some junk character like # is appended after the string.
E.g
Ws-unicode pic X(200)
Ws-national pic N(600)
--let the value in Ws-Unicode is これらの変更は. getting from java end.
move function national-of ( Ws-unicode ,1208 ) to Ws-national.
--after converting value is like これらの変更は #.
i do not want the extra # character added after conversion.
please help me to find out the possible solution, i have tried to replace N'#' with space using inspect clause.
it worked well but failed in some specific scenario like if we have # in input from user end. in that case genuine # also converted to space.
Below is a snippet of code I used to convert EBCDIC to UTF. Before I was capturing string lengths, I was also getting # symbols:
STRING
FUNCTION DISPLAY-OF (
FUNCTION NATIONAL-OF (
WS-EBCDIC-STRING(1:WS-XML-EBCDIC-LENGTH)
WS-EBCDIC-CCSID
)
WS-UTF8-CCSID
)
DELIMITED BY SIZE
INTO WS-UTF8-STRING
WITH POINTER WS-XML-UTF8-LENGTH
END-STRING
SUBTRACT 1 FROM WS-XML-UTF8-LENGTH
What this code does is string the UTF8 representation of the EBCIDIC string into another variable. The WITH POINTER clause will capture the new length of the string + 1 (+ 1 because the pointer is positioned to the next position after the string ended).
Using this method, you should be able to know exactly how long second string is and use that string with the exact length.
That should remove the unwanted #s.
EDIT:
One thing I forgot to mention, in my case, the # signs were actually EBCDIC low values when viewing the actual hex on the mainframe
Use inspect with reverse and stop after first occurence of #

Name of files in a specific directory using matlab

I want to find the name of files in a specific directory. I know that the dir command return the name of files but it contains the file name with the their extension. Therefore, I used strfind to remove the extension of files as follows:
a = dir(fullfile(dataset_path, [dataset_category '\qrel']))
for i= 3: length(a)
name{i} = a(i).name(1:strfind(a(i).name, '.')-1)
I want a better approach without loop. I wonder is it a way to use vectorization for this purpose. I used the following code but it return an error
a = dir(fullfile(dataset_path, [dataset_category '\qrel']))
name = a.name(1:strfind(a.name, '.')-1)
You can do that with regular expressions:
name = regexprep({a.name}, '\.[^\.]*$', '');
This collects all names in a cell array ({a.name}). For each string it matches a dot (\.) followed by zero or more characters other than a dot ([^\.]*) at the end of the string ($), and removes that. Thanks to #Shai for the "other than a dot" correction, which makes sure that only the final dot is matched.

uigetfile not pulling entire file name

I'm using uigetfile to upload my data. I've time stamped my data with a date. So a file I want to upload looks like Data-Dec01_11/45/35.txt The problem is uigetfile reads till the first "/" and then assumes that that is the end of the file name. Thus it pulls the file name Data-Dec01_11. But of course when I load that file it doesn't exist. How do I force uigetfile to pull the entire file name?
You cannot use slashes or backslashes in your file names, as they can be mistaken with the file separator, as in your case.
You can use ´regexpr´ to rename your files so they do not contain illegal characters, as explained in this trhead.
I copy here the code they suggest for your convenience (I've just added a slash and a backslash to the example string so you can see the results):
% these characters are allowed
legalchars = 'a-zA-Z0-9\-\ \_\.' ;
% illegal filename
A = 'Some#charac\ters$are(not&allowed/.txt'
% replace every other character with an underscore
B = regexprep(A,['[^' legalchars ']'],'_')