excel trim function is removing spaces in middle of text - this was unexpected (?) - excel-formula

The excel trim function is removing spaces in middle of text - this was unexpected (?)
i.e. I thought that the excel trim was for trimming leading and trailing spaces.
e.g. a cell value of =Trim("Last Obs Resp") becomes a value of "Last Obs Resp"
Sure enough Microsoft documents it this way:
https://support.office.com/en-gb/article/trim-function-410388fa-c5df-49c6-b16c-9e5630b479f9
I am used to the Oracle database trim function which only removes leading and trailing spaces.
https://www.techonthenet.com/oracle/functions/trim.php
Was excel Trim function always this way?
Excel does not have ltrim and rtrim functions..
i.e. I can't do:
=RTRIM(Ltrim("Last Obs Resp"))
I wonder how I achieve the equivalent in Excel when I don't want to remove doubled up spaces in the middle of the string?
This page documents VBA trim function:
https://www.techonthenet.com/excel/formulas/trim.php

Create a UDF that uses VBA's version of Trim which does not touch the inner spaces. Only removing the leading and trailing spaces
Function MyTrim(str As String) As String
MyTrim = Trim(str)
End Function
Then you can call it from the worksheet:
=MyTrim(A1)
If you want a formula to do it:
=MID(LEFT(A1,AGGREGATE(14,6,ROW($XFD$1:INDEX(XFD:XFD,LEN(A1)))/(MID(A1,ROW($XFD$1:INDEX(XFD:XFD,LEN(A1))),1)<>" "),1)),AGGREGATE(15,6,ROW($XFD$1:INDEX(XFD:XFD,LEN(A1)))/(MID(A1,ROW($XFD$1:INDEX(XFD:XFD,LEN(A1))),1)<>" "),1),999)

Related

Replace the string in all lines of itab?

I am trying to create an algorithm in SAP ABAP to eliminate the word IBAN from certain fields. For example, in the below photo we have that for KNBK-Bankschlüssel=7415000, the KNBK-Bankkontonummer= <IBAN 000000000008. I am trying to eliminate IBAN from the field so that only 000000000008 will be shown in the table.
Is there any string operation that would let me check whether a field has the keyword IBAN and to eliminate it?
Thank you all in advance!
You can do it with the REPLACE statement:
IF word CS 'IBAN'. "to check if the string contains IBAN (as substring)
REPLACE 'IBAN' WITH '' INTO word. "This will remove the substring IBAB, but it will be replaced with a space
CONDENSE word NO-GAPS. "This will remove the space (and other spaces as well, if there is any in the string)
ENDIF.
Looking at the screenshot, the field contains '< IBAN>' (instead of just 'IBAN'), so you have to modify the code accordingly.
Another possibility is REPLACE IN TABLE:
REPLACE ALL OCCURRENCES OF REGEX '^.*IBAN>'
IN TABLE itab WITH ''
RESPECTING CASE.
This snippet will delete all the <IBAN>s with all the preceding characters from all lines.

Escaping quotes and delimiters in CSV files with Excel

I try to import a CSV file in Excel, using ; as delimiters, but some columns contains
; and/or quotes.
My problem is : I can use double quotes to ignore the delimiters for a specific string, but if there is a double quote inside the string, it ignores delimiters until the first double quote, but not after.
I don't know if it's clear, it's not that easy to explain.
I will try to explain with a example :
Suppose I have this string this is a;test : I use double quotes around the string, to ignore the delimiter => It works.
Now if this string contains delimiters AND double quotes : my trick doesn't work anymore. For example if I have the string this; is" a;test : My added double quotes around the string ignore delimiters for the first part (the delimiter in the part this; is is correctly ignored, but since there is a double quote after, Excel doesn't ignore the next delimiter in the a;test part.
I tried my best to be as clear as possible, I hope you'll understand what is the problem.
When reading in a quoted string in a csv file, Excel will interpret all pairs of double-quotes ("") with single double-quotes(").
so "this; is"" a;test" will be converted to one cell containing this; is" a;test
So replace all double-quotes in your strings with pairs of double quotes.
Excel will reverse this process when exporting as CSV.
Here is some CSV
a,b,c,d,e
"""test1""",""",te"st2,"test,3",test"4,test5
And this is how it looks after importing into Excel:
Import your Excel file in openOffice and export as CSV (column escaped with " unlike Excel csv, utf8, comma against ";").

Insert bracket before a =TEXT()

I have a function that shows a begin- and end date. I wanted to have it between brackets in a cell:
=TEXT(A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj")&")
I have the outher bracket already:
Example ->01/01/2017 - 02/03/2017)
But can't seem to try around and insert a bracket in the beginning.
I have tried:
=TEXT((A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj")&")
=TEXT("("A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj")&")
=TEXT(&"("A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj")&")
"("=TEXT(A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj")&")
Why isn't this working?
Use the concatenate function.
Try this: (Convention Changed)
=concatenate("("; TEXT(A1;"dd/mm/jjjj")&" - "&TEXT(B1;"dd/mm/jjjj"); ")")
You can avoid string concatenation by making the extra characters part of the format mask used by the TEXT function. When using reserved characters or symbols that a format mask usually has another purpose for, precede them with a backslash to convert them to a 'string literal'.
=TEXT(A1; "\(dd/mm/jjjj - ")&TEXT(B1; "dd/mm/jjjj\)")

Split string by first delimiter

I have a column with a long list of folder and file names. The folders and file names vary. I want to extract the file name from the column into another column but I struggling to do this in Excel.
Example of column data:(files and folder altered to hide details that should not be public)
c:\data\1\nc2\media\ss\system media\ne\d - wnd enging works v5.swf
c:\data\1\nc2\media\ss\special campaigns\samns dec 2012\trainerv5.swf
C:\Local\Messages\17362~000000001~20131231235910~4.MUF
c:\data\1\nc2\media\ss\system media\tl\nd - tfl statusv4.swf
c:\data\1\nc2\media\ss\system media\core\ss_bagage v2.swf
I know I should be able to search from the right to the first occurence of "\" but I can't figure out the syntax.
Many thanks
UPDATE:
Formula =RIGHT(B2,LEN(B2)-SEARCH("\",B2,1)) should work, but it shows incorrect results. But If I change it to search for "." it pulls out the file extension. So there is a key item I'm missing
=RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
copy it in any column say b drag down,you are done
VBA is a more efficient option if you have many files to parse. Create a module and add the below:
Function GetFileName(file As String) As String
Set fso = CreateObject("Scripting.FileSystemObject")
GetFileName = fso.GetFileName(file)
End Function
There are several different ways to get the text following the last slash in a string, including the following formula. In this example, H15 is the cell containing the string to search. If it can't find a slash, it returns the "-" (dash) character.
=iferror(RIGHT(H15,LEN(H15)-SEARCH("|",SUBSTITUTE(H15,"/","|",LEN(H15)-LEN(SUBSTITUTE(H15,"/",""))))),"-")
The formula first finds the number of slashes in the string. LEN gives the total length of the string, and LEN of the string without slashes after using SUBSTITUTE to eliminate the slashes in the original string - the difference is the number of slashes.
Then, you substitute in a marker character(I used "|") for the last slash. By searching for the marker, you find where the bit after the slash starts. The total length of the string minus where the marker starts tells you how many characters to take from the right, which you then do.
If you need more generic string parsing and are willing to use a little bit of VBA, you can use the split function as suggested by Jamie Bull in his answer to this question on SuperUser.
His function will use any character you choose to split the string into segments and return whichever segment you choose.
I've copied Jamie's function here for convenient reference:
Function STR_SPLIT(str, sep, n) As String
Dim V() As String
V = Split(str, sep)
STR_SPLIT = V(n - 1)
End Function

Removing comma from the string in rdlc

How to remove comma from the end of a string in RDLC text box formula field?
Here is the expression:
=Fields!Titles.Value
If you're sure there won't be any other commas (and are okay with removing all of them), you can replace the commas with nothing, like this:
=Replace(Fields!Titles.Value, ",", "")
If there could be commas elsewhere in the fields that you don't want to remove (and you want to remove commas occurring at the end of the field only), you could do something like this:
=iif(Right(Fields!Titles.Value, 1) = ",",
Left(Fields!Titles.Value, Len(Fields!Titles.Value)-1),
Fields!Titles.Value)
If there can be whitespace before or after the comma, you'll need to add handling for that also (use Trim, LTrim, and RTrim as needed for your situation).

Resources