I want to split an XML Code after an command i.e. ....<car>BMW3</car>
There is a lot of stuff in front of this command so I would like to use the Splitfunction with "<car>" as delimiter.
Is there a way to make this possible or is there another function or VBA code to make this happen?
Thanx in advance :)
That should do it : Replace String with your whole text, and WordDeliminter with your delimiter.
SPLIT(SUBSTITUTE(String,WordDeliminter,";"),";")
Related
I have a problem with an .CSV file.
Some of the values are prices with a comma to separate units and decimals, all the other fields are separated with a comma too.
So, as expected, it is impossible to convert my csv file like this. (If there is a way, please tell me)
Therefore, I am trying to write a vba macro that will replace the comma by a dot.
More specifically, I need to replace the 9th occurence of "," to a "." IF AND ONLY IF the character next to the comma respects a specific condition. That is why I need a macro to do so.
In excel, I was using the following formula to find the position of my comma:
=Find(char(160),substitute(A2;",";char(160),9))
This formula gives me the position of the 9th comma, that's perfect. I would like to know how to code this in VBA
Thanks in advance !
Alex
I have about 200 strings that I need to manipulate to make my SQL querying easier. Suppose I have a string like
OR this.quantity LIKE 'transient' OR this.quantity LIKE 'gradient'
I would like to add wildcards to the beginning and end of 'transient' and 'gradient' as such:
'%transient%', '%gradient%'
Suppose further that I have about 198 more of these (unique of course). Is there a function I can use for this manipulation or do I need to write my own VBA code to accomplish this?
You are not using wildcards, so in SQL, you would just use in:
this.quantity IN ('transient', 'gradient')
If you can't edit/replace, you'd have to get into text parsing formulas. With your example above in A2, the formula to replace the first two quotes would be
=LEFT(A2,SEARCH("'",A2))&"%" &MID(A2,SEARCH("'",A2)+1,SEARCH("'",A2,SEARCH("'",A2)+1)-SEARCH("'",A2))&"%"
Yes its ugly and I didn't write it from scratch. Use the search function to find the ' Then put the text in. The second ' is searching the same string, but using the place of the FIRST ' as the starting point; +1. Not sure if it's the BEST way, but I've used Excel to do many text manipulations in the past.
I have a csv file, when i use the split function, my issue is that the 16th segment of the array has a name in it (in most cases) that has first and last name split by a comma. This obviously causes me issues as it puts my array out of sync. any suggestions on how i can handle this?
the string in the 16th segment is surrounded by "" if that helps, the split function still splits it though.
you can use TextFieldParser as indicated here
I recommend Lumen CSV Library, it can correctly handle field values with commas.
Also it has a very good performance, and a very simple usage.
See the link above, it won't disappoint you.
I think you're missing the point. Split is only good for simple csv parsing. Anything that gets even a little complicated means a lot of extra code. Something like the TextFieldParser is better suited to what you want. However if you must use Split here's one way:
Dim TempArray() As String
Dim Output As New List(Of String)
If SourceString.Contains("""") Then
TempArray = SourceString.Split(""""c)
Output.AddRange(TempArray(0).Split(","c))
Output.Add(TempArray(1))
'If the quoted part of the csv line is at the end of the line omit this statement.
Output.AddRange(TempArray(2).Split(","c))
Else
Output = New List(Of String)(SourceString.Split(","c))
End If
This assumes that the data is strictly organized, except for the quotes, if not you'll have to add validation code.
Split by "," with the quotes instead of just a comma. Don't forget to take care of the first and last quotes on the line.
i have a word document containing several strings. These strings have the first part always the same, for example ABC_001, ABC_002, ABC_003. I need to search for "ABC_" substring in the doc, extract all the occurences ("ABC_001", "ABC_002", "ABC_003") and copy them in an Excel sheet.
Anyone can help?
Thanks in advance.
You can reference the VBScript Regular Expressions 5.5 and regex them.
Have a look at http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/
and http://txt2re.com/
and some of VBA multiple matches within one string using regular expressions execute method
EDIT:
Actually it is probably easier to go to data and "Get external data" choose de-limiter and import, either manually or record a macro to get a feeling for the vba structure.
This should get you all the entrys in seperate cells, then go over them with a MID to get the part you need
I've come across a character in one of my data feeds, which I have never encountered before
The images above are the data feed in Notepad++ and Notepad view. As you can see it appears as 'BEL' in Notepad++ and a sort of 'bullet point' in Notepad.
How would I go about replacing this character in vb.NET?
I've tried a simple replace in a SSIS Script Task by copying and pasting the character into the replace function, e.g.
text = text.Replace("copy and pasted character", "")
and this gives this error
All help is extremely appreciated,
Thanks
I’ve got no idea what SSIS is but since you wanted to know a solution in VB.NET, the code you’ve tried will work here. That is:
text = text.Replace("copy and pasted character", "")
will work just fine in VB. Alternatively, you can use the following:
text = text.Replace(Chr(7).ToString(), "")
Find out what the Ascii value of the character is and then use the Chr function to eliminate it
i.e.
text = text.Replace(Chr(n), "")
[Bell] is probably character 7