Reading a RO property of a link ,how to extract the desired string - vbscript

UFT-vbScript- I am reading a getROproperty of a link from an application.And the link has 300 different values following similar class pattern for many links like [PDF LLC- USA , [PDF MMB CANADA ,[PDF MCCS AUSTRALIA ,[PDF SSC MEXICO. [PDF ACCS MEXICO My question here is I just want to display the country name removing the other associated strings .How will I achieve this progamatically using vbscript. one way of doing this is using SPLIT fxn , but the real question is how will one know which pattern to choose from .

You should always post a sample code which you have tried along with your question.
If there is always a space (" ") just before your country name, use space to split up like the below
strExtractedValue = "[PDF LLC- USA"
arrExtract = Split(strExtractedValue , " ")
strCountryName = arrExtract(2) ' the 3rd element

Related

Import xml for query of Google Sheet

I am getting no data when I apply class using importxml, I have reviewed the source code by using right click page source option and sentencs are there, I used ctrl+f to find the line and tried the xpath as mentioned below but it gives #NA, since new to import XML google sheets query, I need the result that is attached in the snap below for cell E55 the Japanese and English sentence in cell I55 & J55.
These sentences came from the following search the first sentence is used always in Japnese & English, here is the snap
I have tried a few combinations but in shows #NA;
=IMPORTXML("https://tangorin.com/sentences?search=時","//div[#class='s-jp']")
=IMPORTXML("https://tangorin.com/sentences?search=時","//div[#class='entry entry-border sentences undefined ']/dd[#class='s-jp']")
Can anyone please assist as can I cant copy for 2000 letters both Japnese & English sentences which I need for translation class, much appreciated thanks
Output :
3 formulas to get the data (url is in cell D2).
For Kana in D4 :
=TRANSPOSE(SPLIT(SUBSTITUTE(TEXTJOIN("",TRUE,IMPORTXML(D2,"//div[#class='results-main-container']//dt//text()[not(parent::rt)]|//dd[#class='s-en']/#class")),"s-en","¤"),"¤"))
For Romaji in E4 :
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(SUBSTITUTE(TEXTJOIN(" ",TRUE,IMPORTXML(D2,"//div[#class='results-main-container']//dt//rt|//dd[#class='s-en']/#class")),"s-en","¤"),"¤"))))
For English in F4 :
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REGEXREPLACE(TEXTJOIN(" ",FALSE,IMPORTXML(D2,"//div[#class='results-main-container']//dd/span|(//dd[#class='s-en'])[not(position()=1)]/#class")),"(\w)( )(\w)","$1'$3"),"s-en","¤")," , ",", ")," . ",".")," - ","-")," ( "," (")," ) ",") ")," !","!")," ?","?"),"¤"))))
To limit the array to 1 result, you can use something like :
=INDEX(one of the preceding formulas,1,1)
Output :
EDIT : If you need something like this (word in a cell and first example retrieved. /!\ Limit the number of words to search. Each word = 3 IMPORTXML requests. So, for 20 words => 60 requests, leading to a slow sheet.)
In column B, copy-paste the words to search.
For Kana in cells C3,C4,C5,... the following formula :
=TEXTJOIN("",TRUE,IMPORTXML("https://tangorin.com/sentences?search="&B3,"(//div[#class='results-main-container']//dt)[1]//text()[not(parent::rt)]"))
For Romaji in cells D3,D4,D5,... the following formula :
=TEXTJOIN(" ",TRUE,IMPORTXML("https://tangorin.com/sentences?search="&B3,"(//div[#class='results-main-container']//dt)[1]//rt"))
For English in cells E3,E4,E5,... the following formula :
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REGEXREPLACE(TEXTJOIN(" ",FALSE,IMPORTXML("https://tangorin.com/sentences?search="&B3,"(//div[#class='results-main-container']//dd/span)[1]")),"(\w)( )(\w)","$1'$3"),"s-en","¤")," , ",", ")," .",".")," - ","-")," ( "," (")," ) ",") ")," !","!")," ?","?"),". ",".")

How to convert format of number from English to Italian with VBScript?

I need to convert the English numbering to Italian.
I tried using multiple replacements but I don't think it's the right method.
price = Replace(price, ".", ",")
The problem is that when I have too large numbers I get replaced several times and the wrong numbers come up.
For example:
English version: 3,450.108
After replacement: 3,450,108 (but it's wrong)
Correct format: 3.450,102
Would not recommend manually replacing values in an attempt to get the correct format when VBScript can already do it for you using the SetLocale() Function in conjunction with the FormatNumber() Function which will return the string representation of that number for the specific locale.
Note: Remember that the actual value and how a value is displayed are two separate things (see the example below).
Option Explicit
Const decimalplaces = 3
Dim price: price = 3450.108 'This is the raw value from your data source.
Call SetLocale("en-gb")
Call WScript.Echo("English (UK) price: " & FormatNumber(price, decimalplaces))
Call SetLocale("it-it")
Call WScript.Echo("Italian price: " & FormatNumber(price, decimalplaces))
Output:
English (UK) price: 3,450.108
Italian price: 3.450,108
If you want to swap 2 delimiter characters you need to use a temp character for the second one, otherwise you won't be able to distinguish between the original second delimiter and the replaced first one.
price = Replace(price, ".", "_")
price = Replace(price, ",", ".")
price = Replace(price, "_", ",")

Excel Power Query: How to Combine All List Items into Single Row

I have a query to the Cognitive text keyphase API from Microsoft from '16 Excel Power Query - getting keywords from tweets. Works fine.
However, the JSON doc that's returned per query is converted by Power Query into a list of ~1-5 rows.
In the case of the pic, I want all responses returned to be in one cell/row, regardless of the number of items returned.
Here is my full M query (you need to put your own key in) if you're interested.
let
TweetCognitive = (TweetID as text, TweetText as text) =>
let
JsonRecords = Text.FromBinary(Json.FromValue([id=TweetID, text=TweetText])),
JsonRequest = "{""documents"": [" & JsonRecords & "]}",
JsonContent = Text.ToBinary(JsonRequest, TextEncoding.Ascii),
Response =
Web.Contents("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases?",
[
Headers = [#"Ocp-Apim-Subscription-Key"="yourkeyhere",
#"Content-Type"="application/json", Accept="application/json"],
Content=JsonContent
]),
JsonResponse = Json.Document(Response,1252)
in
JsonResponse
in
TweetCognitive
You can use List.Accumulate to turn a list of values into a single value. For example, this would combine the values in the list into a single text value with ". " separating each row's value:
List.Accumulate(JsonResponse, "", (state, current) => state & current & ". ")
This would generate "monday frank love happiness today. nice good kind. tomorrow. " in your example. If you want to get rid of the trailing space, you can surround the List.Accumulate expression with Text.Trim.
The basic function to concatenate elements in a list is Text.Combine. For instance:
Text.Combine(JsonResponse, " ")
This avoids the extra delimeter at the end you get with List.Accumulate. Note also List.Combine is for creating a longer combined list from shorter lists, and the similar naming there may cause confusion.

How to solve invalid parameter error using Codeigniter and Pesapal

Am trying to test my payment module using codeigniter and pesapal but I keep getting this error "Problem: parameter_rejected | Advice: invalid_value_for_amount> oauth_parameters_rejected | Ksh.4%2C999".
Where Ksh. 4%2C999 is the bill ksh. 4999. I have used the right Pesapal keys so I don't know what am doing wrong.
Problem
Your amount has a thousand separator ... something like this Ksh.4,999 instead of passing a value that's an integer like 4999.
Either you are passing in the amount with the comma (which you can fix by removing the comma in your logic) or the number_format() method is adding the thousand separator (explanation given below in solution).
Solution
According to the PHP docs number_format() does something like this (basic case only)...
// english notation (default)
$english_format_number = number_format($number);
// 1,235
Note how it's added a , as the thousand separator. This is what is being converted(encoded) to %2C. Pesapal doesn't understand numbers with the , which is what you are passing to them. ... to stop the function from using the thousands operator do something like this ...
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
3rd parameter specifies the decimal separator (which is .) and the 4th specifies the thousand separator (which is an empty string).
But as #BabyAzerty has said, without code there's nothing much that we can work with to assist you. I'll amend the answer the more context you give to your problem but the above is pretty much what I've seen wrong with your implementation elaborated in the question and comment above.
$amount1 = (integer)$data->amount;
$amount = number_format($amount1, 2, '.', '');//format amount to 2 decimal places
$desc = $data->phone_type;
$type = "MERCHANT"; //default value = MERCHANT
$reference = $data->reference;//unique order id of the transaction, generated by merchant
$first_name = $data->name1;
$last_name = $data->name2;
$email = $data->email;
$phonenumber = $data->mobile;//ONE of email or phonenumber is required
This error means that your account on Pesapal has a limit on the amount it can transact. By default the amount is usually set to USD 10 or the equivalent of it in local currency.
You need to contact the team at support.pesapal.com to complete your sign-up by submitting contract and documents for your business in order to have the account activate for full transactions.

how to split, remove part of data in column with ;

I am using the Spreadsheet gem.
My code is:
book = Spreadsheet.open 'excel-file.xls'
sheet = book.worksheet 0
book.write 'output-file.xls'
I want to remove data that comes after ";" in a column:
FULTON BANK NA;FULTON BANK
I just want it to be FULTON BANK NA for example.
Also, I want to leave price data like this: $78,000.00 and want to strip
all other data from a specific column:
MORTGAGE - CORPORATE;($78,000.00)
I just want it to be $78,000.00 for example.
You could do it this way:
s = 'FULTON BANK NA;FULTON BANK'
s = s[/[^;]+/]
that will leave every before the first semicolon in s. Or you could it like this:
s = s.split(';')[0]
Or
s.gsub!(/;.*/, '') # This modifies s in place
For the second one, it depends on the format of your data but you could start with this:
s = 'MORTGAGE - CORPORATE;($78,000.00)'
s = s[/\(([^)]+)\)/, 1]
Or, if the last component may or may not have parentheses, you could do something like this:
s = s.split(';')[-1].tr('()', '')
That will split s into pieces at the semicolons (split(';')), take the last component ([-1]), and then remove any parentheses that there (.tr('()', '')).

Resources