I'm trying to parse the first and last name into their own variables. I figured out how to get the first name, but I can't get the last name. Any help would be appreciated. I'm reading the data off the clipboard.
Clipboard = John Smith
RegExMatch(clipboard, "(^([\w\-]+))", FirstName)
RegExMatch(clipboard, " ", LastName)
For this very specific example, you could probably use $ at the end instead of ^ at the beginning, as in "(([\w\-]+)$)".
Related
I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word in a string with another word but not replace any other occurrences of that word. for an example take the string:
My name is Bob, her name is Sara.
I would like to replace the first occurrence of name with baby so the resulting string would be
My baby is Bob, her name is Sara.
I have been working in https://regex101.com/ to try to build and see what is selected as I go but as I said none of these have a powershell flavor of regex. In that I can just turn off the global flag and it seems to select the first occurrence but not in powershell. So I am really at a loss of where to begin all really have at this point is selecting all occurrences of the word namewith:
$test = "My name is Bob, her name is Sara."
$test -replace 'name', 'baby'
One way to replace n times:
$test = "My name is Bob, her name is Sara."
[regex]$pattern = "name"
$pattern.replace($test, "baby", 1)
> My baby is Bob, her name is Sara
You could capture everything before and behind and replace it:
'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2'
I have to make sure each line has 4 columns, but the input data is quite a mess:
The first line is header.
The second line is valid as it has 4 columns.
The third is also valid (it's ok if the description field is null)
ID field and "god bless me" Last column PNumber is are not null fields.
As one can see 4th line is messed up because of newline character in "Description column" it spanned across multiple lines.
ID Name Description Phnumber
1051 John 5674 I am doing good, is this task we need to fix 908342
1065 Rohit 9876246
10402 rob I am
doing good,
is this task we need to fix 908341
105552 "Julin rob hain" i know what to do just let me do it
"
"
"
"
"
"
908452 1051 Dave I am doing reporting this week 88889999
Maybe a screenshot will make it easier to see the problem
Each line will start with a number and ends with a number. Each line should have 4 columns.
desired output
ID Name Description Phnumber
1051 John 5674 I am doing good, is this task we need to fix 908342
1065 Rohit 9876246
10402 rob I am doing good, 563 is this task we need to fix 908341
105552 "Julin rob hain" i know what to do just let me do it 908452
1051 Dave I am doing reporting this week 88889999
The data is sample data the actual file has 12 columns. yes in between columns can have numbers and few are date fields (like 2017-03-02)
This did the trick
cat file_name | perl -0pe 's/\n(?!([0-9]{6}|$)\t)//g' | perl -0pe 's/\r(?!([0-9]{6}|$)\t)//g' | sed '/^$/d'
awk to the rescue!
assumes the all digit fields don't appear except first and last fields
awk 'NR==1;
NR>1 {for(i=1;i<=NF;i++)
{if($i~/[0-9]+/) s=!s; printf "%s", $i (s?OFS:RS)}}' file
ID Name Description Phnumber
1051 John I am doing good, is this task we need to fix 908342
10423 rob I am doing good, is this task we need to fix 908341
1052 Julin rob hain i know what to do just let me do it " " " " " " 908452
1051 Dave I am doing reporting this week 88889999
perhaps set the OFS to \t to have more structure
I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word in a string with another word but not replace any other occurrences of that word. for an example take the string:
My name is Bob, her name is Sara.
I would like to replace the first occurrence of name with baby so the resulting string would be
My baby is Bob, her name is Sara.
I have been working in https://regex101.com/ to try to build and see what is selected as I go but as I said none of these have a powershell flavor of regex. In that I can just turn off the global flag and it seems to select the first occurrence but not in powershell. So I am really at a loss of where to begin all really have at this point is selecting all occurrences of the word namewith:
$test = "My name is Bob, her name is Sara."
$test -replace 'name', 'baby'
One way to replace n times:
$test = "My name is Bob, her name is Sara."
[regex]$pattern = "name"
$pattern.replace($test, "baby", 1)
> My baby is Bob, her name is Sara
You could capture everything before and behind and replace it:
'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2'
Addresses in Salesforce are a structured compound data type. As such, different fields exist for the street, city, state, and country. The street field is a single field. How does one import multi-line street addresses such as:
1 Street Line
2 Street Line
3 Street Line
City, State, 12345
Country
using DBAmp?
The key is to embed newline characters \n in the field value with the T-SQL char() function. Thus, the solution is:
address1 + char(10) + address2 [+ char(10) + addressN ]
Well, have you run into any trouble?
On Account the BillingStreet / ShippingStreet is a textarea field. Meaning good old newline character \n should do just fine, as long as the total length < 255.
Map the remaining address components to BillingState etc and you're good to go?
Sorry if the answer is a bit generic but as stupid as it sounds - try it out on few acconts before full import and you should get the hang of it. Unless it's a question about string splitting in SQL Server...
I'm trying to include the internationalization of my application, and only for testing purposes I added a simple line in the file Localizable.string.
This is my whole file:
"Test locale" = "Test locale"
And when I try run my application I get this error:
Localizable.strings:0: error: validation failed: The data couldn’t be
read because it has been corrupted.
I've tried changing the "Text Encoding" to UTF-16 but nothing resolved.
If this is your whole file, add a semicolon at the end. Change it to:
"Test locale" = "Test locale";
To get more detailed informations you can use the Property List utility from the command line:
plutil -lint <your_strings_file>.strings
the -lint switch is for checking the syntax. If you have an error you'll get line number and more informations, and in general better directions on how to fix the issue.
You can verify your Localizable.strings file with this script:
https://github.com/dcordero/Rubustrings
In my case, it was like this:
/* Comment for Very Long Sentence */
"Very Long Sentence Very Long Sentence Very Long Sentence Very Long Sentence " =;
"Very Long Sentence Very Long Sentence Very Long Sentence Very Long Sentence ";
(Notice the ' = ; ' instead of ' = ' at the end of the first line)
In my case it was brackets inside string — I needed to add slash before \".
I've made a little script to check whole folders .strings files using plutil.
https://github.com/CarlesEstevadeordal/check_strings
There can be multiple reasons for this:
Semicolon is missing at the end.
Multiple semicolons at the end.
" within the message which should be escaped by \".
Extra character after semicolon.
Invalid white space in the file.
Other invalid characters in the file.
Merge conflict characters in the file!
<<<<<<< HEAD, ======= and >>>>>>>.
Please note that plutil -lint Localizable.strings returned OK for point-2 & 7!