How Do I get this Split Function to Work? (VB.NET) - vb.net

So, I made a program that for the most part, converts numbers to letters. My problem before was it was converting each individual digit instead of each number e.g. (1-0-1 instead of 101). Someone suggested that I use the Split function:
Dim numbers As String() = DTB.Split(" ")
So now it's reading the number all the way through being that it will only the split if there's a space in between. My problem now is that it's translating for example: "[102, 103, 104]" as "[102", "103" and "104]" because it will only split if there's a space between. Obviously, you can't convert "[102" or "104]" because they aren't actual numbers.
Does anyone have a solution on what I should do to get this to convert no matter the spacing? Would Regex be the way to go?

use a regular expression with \d+ it will match numbers
so
12234abcsdf23434
will return two matches
12234
23434

Related

REGEX_EXTRACT for specific pattern inside brackets

Trying to use REGEX_EXTRACT in SQL to extract certain string patterns inside Brackets.
So I have tried this formula: REGEX_EXTRACT(column, r'\[(.*?)\]'), but problem is that there are multiple Brackets in the same cell, and this formula will only extract the first string pattern in the first bracket.
So, what I'm trying to figure out is how can I extract specific patterns within the Brackets? The pattern I'm looking for looks like this: [xx-XX]
Where x can be any string in the alphabet.
Any tips or directions would be greatly appreciated
This should work if you always have 2 lowercase letters followed by '-' and then followed by 2 uppercase letters:
\[([a-z]{2}-[A-Z]{2})\]

Finding strings between dashes using REGEXP_EXTRACT in Bigquery

In Bigquery, I am trying to find a way to extract particular segments of a string based on how many dashes come before it. The number of total dashes in the string will always be the same. For example, I could be looking for the string after the second dash and before the third dash in the following string:
abc-defgh-hij-kl-mnop
Currently, I am using the following regex to extract, which counts the dashes from the back:
([^-]+)(?:-[^-]+){2}$
The problem is that if there is nothing in between the dashes, the regex doesn't work. For example, something like this returns null:
abc-defgh-hij--mnop
Is there a way to use regex to extract a string after a certain number of dashes and cut it off before the subsequent dash?
Thank you!
Below is for BigQuery Standrd SQL
The simplest way in your case is to use SPLIT and OFFSET as in below example
SELECT SPLIT(str, '-')[OFFSET(3)]
above will return empty string for abc-defgh-hij--mnop
to prevent error in case of calling non-existing element - better to use SAFE_OFFSET
SELECT SPLIT(str, '-')[SAFE_OFFSET(3)]

How can I add a string character based on a position in OpenRefine?

I have a column in Openrefine, which I would like to add a character string in each of its rows, based on the position in the string.
For example:
I have an 8th character number string: 85285296 and would like to add "-" at the fourth place: "8528-5296".
Anyone can help me find the specific function in OpenRefine?
Thanks
Tzipy
The simplest approach is to just use the expression language's built-in string indexing and concatenation:
value[0,4]+'-'+value[4,8]
or more generally, if you don't know that your value is exactly 8 characters long:
value[0,4]+'-'+value[4,999]
Possible solution (not sure if it's the most straightforward):
value.replace(/(\d{4})(.+)/, "$1-$2")
This means : if $1 represents the content of the first parenthesis/group in the regular expression before and $2 the content of the second one, replaces each value in the column with $1-$2.
Some other options:
value.splitByLengths(4,4).join("-")
value.match(/(\d{4})(\d{4})/).join("-")
value.substring(0,4)+"-"+value.substring(4,8)
I think 'splitByLengths' is the neatest, but I might use 'match' instead because it fails with an error if your starting string isn't 8 digits - which means you don't accidentally process data that doesn't conform to your assumption of what data is in the column - but you could use a facet/filter to check this with any of the others

How to Trim right and left a String in VB .net

I want to take the value of
T.GS.+0.220kg
but I don't know how to remove the string.
I just want to take numbers from the weight.
like 0.220
Can someone help me ?
You can make use of the Regular Expressions to extract a decimal value from basically any string. First you'd need to import the library:
Imports System.Text.RegularExpressions
Then using this will return just the decimal value:
Regex.Match("T.GS.+0.220kg", "\d+.\d+").Value
This particular expression looks for a digit or digits, followed by a point (dot), followed by another number of digits, so the previous points (in between T and G for example) aren't included.
This returns exactly 0.220, you can then replace the string with any string variable and assign this expression as needed.
If you havn't worked with regular expressions before and want somthing that looks a little nicer. You could use the string.split method.
dim input as string = "T.GS.+0.220kg"
input = input.split("+")(1) ' which will grab the "0.220kg"
input = input.substring(0, input.length - 2) ' then filter off the last 2 chars
In english:
split the string into 2 seperate pieces grabing the part to the right of the first '+' symbol.
Then remove the last 2 chars from the end.

Objective C Regex- Numbers in NSStrings

I have a number of NSStrings I need to parse/regex and get the numbers 187,215; 181,170; 69,63; etc etc out.
a:2:{i:0;s:3:"187";i:1;s:3:"215";}
a:2:{i:0;s:3:"181";i:1;s:3:"170";}
a:2:{i:0;s:2:"69";i:1;s:2:"63";}
Anyone can help out?
Assuming:
The items you are trying to grab are only numbers (with no other chars inside).
If you know your numbers (or whatever inside the quotes) is what you need, you can search for the quotes that surround them.
The quotes are only used to contain the item (digits) you are searching for.
If you want numbers and surrounding quotes
"\d+?" Example
This will grab any digits (one or more digit due to the +) inside of quotes. Since regex is normally "greedy", adding the ? after the + will make it "non-greedy", or it will stop processing and looking for digits after it hits the NEXT quote instead of processing until it find the last quote.
If you want just the numbers
(?<=")\d+?(?=") Example
This is similar to the previous regex, the only difference is the exclusion of the quotes from the returned item. Including the quotes in the regex will match them positively and then return them back. This regex uses positive look-ahead and look-behinds to ensure that the pattern we are looking for \d+? is preceded by a quote and followed by a quote.