I want to split a string based on the lines, meaning seperating contents on seperate lines.
Example -
Hello I
am
Bill Gates
Final Array should be ["Hello I","am","Bill Gates"]
I tried using split function and passing '\n' but it ain't working.
<#assign finalValue = body?split('\n') />
I am not getting the desired result in this case. Can you please help me out with this?
For more details, read below -
I am trying to fetch country from an address. Country is always on the last line of address, so I am trying to SPLIT the address based on lines, thus fetching last line which is the desired output.
Example -
ABC, Industries Ltd.,
XYZ Street,
United States.
So here, I am using split function as address?split("\n") but it ain't working.
So, I tried splitting using Developers Console and it worked fine there. Used split() function.
Upon fetching the address value though, I am getting it as -
ABC, Industries Ltd., \n XYZ Street, \nUnited States.
Hence, thought of splitting using \n but it ain't working!
The usual problem is that there are 3 kind of line-breaks in use: \r\n (Windows and some Web protocols), \n (everything else), and very rarely \r (old Mac). The split that works with all is ?split(r'\R', 'r'). Note that the R is capital in \R. That's a regular expression construct, supported since Java 8.
Likely doesn't help the OP, but might help someone else from the frustration of trying to split on line break for an advanced PDF in NetSuite using Freemarker!
You need to use <br />
${var?split(r"<br />", "r")}
Related
In the below string, i need to replace the string as space (' ') which starts from DND_NCP_TEXT_START and end at DND_NCP_TEXT_END. without hardcode the string or without store it in variable. any possible using regular expression?
String:
'Dear DND_CST_NAME_STARTHARRIET SCOTT
:DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY SHORT
:DND_NCP_NAME_END
DND_ATTORNEY_TEXT_START
Our records indicate that you represent
DND_CST_NAME_STARTHARRIET D SCOTT
DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY A SHORT
DND_NCP_NAME_END in the above referenced child support matter. Please contact your client regarding this matter and advise us as soon as possible.
If you are no longer representing
DND_CST_NAME_STARTHARRIET D SCOTT
DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY A SHORT
DND_NCP_NAME_END, please file a Notice of Withdrawal.
DND_ATTORNEY_TEXT_END'
needed output:
start string DND_NCP_NAME_START and end string DND_NCP_NAME_END and string inside this need to remove
The problem of your expression is, that you have 2 such patterns in the text, but since the default algorithm used is greedy one, the whole string starting from the 1-st DND_NCP_TEXT_START and ending with the last DND_NCP_TEXT_END is removed.
Use non-greedy matching (.*?) as in the example below.
SELECT
REGEXP_REPLACE
(
'DND_ATTORNEY_TEXT_START Dear EDWIN Our records indicate that you represent HARRIET D SCOTT in the above referenced child support matter. DND_NCP_TEXT_START Please contact your client regarding this matter and advise us as soon as possible.DND_NCP_TEXT_END Please co-operate.DND_NCP_TEXT_START Please contact your client regarding this matter and advise us as soon as possible.DND_NCP_TEXT_END We are anticipating your reply. Thanks a lot. DND_ATTORNEY_TEXT_END'
,'DND_NCP_TEXT_START.*?DND_NCP_TEXT_END',''
)
FROM SYSIBM.SYSDUMMY1;
I'm writing a script to scrape from another website with Python, and I am facing this question that I have yet to figure out a method to resolve it.
So say I have set to replace this particular string with something else.
word_replace_1 = 'dv'
namelist = soup.title.string.replace(word_replace_1,'11dv')
The script works fine, when the titles are dv234,dv123 etc.
The output will be 11dv234, 11dv123.
However if the titles are, dv234, mixed with dvab123, even though I did not set dvab to be replaced with anything, the script is going to replace it to 11dvab123. What should I do here?
Also, if the title is a combination of alphabits,numbers and Korean characters, say DAV123ㄱㄴㄷ,
how exactly should I make it to only spitting out DAV123, and adding - in between alphabits and numbers?
Python - making a function that would add "-" between letters
This gives me the idea to add - in between all characters, but is there a method to add - between character and number?
the only way atm I can think of is creating a table of replacing them, for example something like this
word_replace_3 = 'a1'
word_replace_4 = 'a2'
.......
and then print them out as
namelist3 = soup.title.string.replace(word_replace_3,'a-1').replace(word_replace_4,'a-2')
This is just slow and not efficient. What would be the best method to resolve this?
Thanks.
I have a calculation which will remove a blank space and replace with a full stop. This is correct for 90% of my cases. However, sometimes two blanks will appear in my value. For the second space I want to delete it. Is this possible?
I think it may be possible using a code stage, but I am not sure what the code would be.
My current calculation is Replace([Item Data.Name], " ", ".")
Example data John B Smith I want the result to be John.BSmith
For anything that'd like to do with the strings, there is a really powerful tool called Regular Expressions (regex). I encourage you to play with it, because it's a really powerful tool in the hands of RPA developer.
To replace the second space in any string with a "." you can use the following action.
Object: Utility - Strings
Action: Regex - Find and Replace
Input:
Regex Pattern: "(?<= .*) "
Text: "John B Smith"
Replacement: "."
The above action is not a standard Blueprism one, so it has to be added to your VBO. The action looks as follows:
The VB.net code for that action is as follows:
Dim R as New Regex(Regex_Pattern, RegexOptions.SingleLine)
Dim M as Match = R.Match(Text)
replacement_result = R.Replace(Text,Regex_Pattern,replacement_string)
There might be a need for some additional assemblies, so please see below a printscreen of references and namespaces used in my object:
I resolved this issue by using the Utility - Strings object and the split text action. I split my name by space. This outputted a collection which I was then able to loop through and add a full stop after the fist instance but then trim the other instances.
Please see screenshot
I think the simplest solution would be
Replace(Replace(Text," "," ")" ","."))
if you know that it will give one or two spaces
First replace the two white spaces to single and then again single white space to dot(.)
I need to get the pieces of text out of text)). Very simple example actually, but gives me quite some pain.
Here is the sample text, it is an email template:
{!Account.Name}
Hi hi there {!Account.Id + 'cool'}.
Very interesting stuff - {!Contact.Description}
Now we get {!Contact.Description + Contact.Email__c}
So I need all the occurances of text like Account.Name, but only those which are within opening "{!" and closing "}" tags.
What is the simplest/starting approach to do it? Note that in case of the last line, I need to get the two occurances, Contact.Description and Contact.Email__c.
Thanks a lot for any help!
I would just do a plain text search for {...} blocks and parse their content with a simple expression parser. Don't try to come up with a parser that gets all the text and must be prepared to deal with any rubbish that can come in outside of the blocks (which could ultimatively lead to security problems).
In my project I am developing teachers and their timetable. I was provided with a text file that contains the teacher timetable from my uni. They ware unable to tell me what is the syntax or code language so I would know how to read it and use it in my iPhone app. Can you help me identifying what sot of code is this and how can I read that?
Sample:
SEM1:3ENCE_B:NW:NG102:EECT300:120:0900:2
SEM1:3ENCE_B,3ENCE_C:TW:NLG107:EEEL300:120:0900:1
19:3ENCE_A,3ENCE_B,3ENCE_C:TW:CLG.01:EEEL305_L:120:1100:1
19:3ENCE_A,3ENCE_B,3ENCE_C:TW:NLG107:EEEL305:120:0900:1
SEM1:3ENCE_A,3ENCE_B:TW::EEEL300:120:1100:4
SEM1&2:3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:SK:CLG.06:EEEL315_L:120:1400:4
SEM1:3CS_A,3CS_B,3CS_C,3CS_D,3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:DHE:CLLT:EICG301_L:120:0900:5
SEM1:3CS_A,3CS_B:ABO,DHE:N5.114:EICG301:120:1100:5
SEM1:3CS_A,3CS_B,3CS_C,3CS_D,3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:NW:LTS205:EECT300_L:120:1600:2
27:3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_CS::NG100:EEEL320:120:1100:2
SEM1:3CS_A,3CS_B,3CS_C,3CS_D:NW:C2.14:ECSC302_L:120:0900:3
SEM1:3CS_A:NW:NG100:EECT300:120:1400:2
It's not code, it's data. And the best way of interpreting it is to compare this representation with another : Think Rosetta Stone.
Obviously, colon is used to separate the fields, and each line probably represents a single tinmetable item. Each line appears to have 8 fields on it.
One field looks like a course ID : EECT300
Another looks like a time : 0900
As for the rest, you'll have to work it out...
University of Westminster, maybe...?
It is not a code language.
It is just a plain text file which contains data using colons : as a separator
I guess you have to parse it and retrieve the information for each column. You have to be aware of the signification of each column (if no ask to your uni)