Give tab spacing after first word in text file - language-agnostic

Consider I have a .txt file as of the format,
Name: Abc
Id: 123
Age: 12
Address: xyz
I want to convert this file of the form,
Name : Abc
Id : 123
Age : 12
Address : xyz
i.e the Colon after each tile should move 2 or 3 tab spaces. The title will be only a single word and wont have spaces. So the title wont be of the form(Your age:). So i can just read the first word and give tabs after that.
How can i do this? and will doing in perl be simpler or any other language.?

Find the length of the biggest word, add n spaces to it. That's the padding to use when formatting each word.
PHP, for example, has a sprintf() function that you can look at. Various other languages provide formatted output as well.
In PHP, the following format should work - "%-<max>s : %s", where <max> is the length of the biggest word + some padding.
sprintf("%-25s : %s", $key, $value);
- makes the string left aligned.

Related

thymeleaf text mode string how to keep indent for each line

i have a string stored in database which contains line break, it should looks like following when displaying on page:
abc
def
hkg
now i need to add this string to an email dialog as email content and its format should be:
my thymeleaf text template to generate email content looks like:
Test: [# th:each="g : ${gList}"]
Description:
[(${g.descr})]
However, after i added the template content to a textarea, it is:
that is there is no indent from line 2, this is not what i want.
how can i get the format like following for one string which contains multiple lines?
Test:
Description:
abc
def
hkg
The html code to show the email content in dialog is :
<div class="row">
<label class="col-2 text-right">Content:</label>
<textarea id="emailContent" class="col-9" v-model="email.content" >
</textarea>
</div>
another question is : what if this string is long but no line break, it only has spaces between words. in this case, it still display the rest of this string from line 2 without indent.
The string stored in the database is abc\ndef\nhkg therefore when you print it out you are getting:
Test:\n
....Description:\n
........abc\n
def\n
hkg
Since this is plain text and you don't have any of the formatting capabilities of html, you're going to have to modify the string itself. Basically, you need to replace your newlines \n with 8 spaces and a new line. You want the string to look like:
abc\n........def\n........hkg
As for what that looks like in Thymeleaf. Kind of ugly, but I think this should work for you:
Test: [# th:each="g : ${gList}" th:with="newline=${T(System).getProperty('line.separator')}"]
Description:
[(${#strings.replace(g.descr, newline, newline + ' ')})]

What pattern to use in a html input field to validate french numbers format?

I am looking for the right pattern allowing to validate french numbers (positive integers) in an HTML input.
i.e. thousand separator is a "space".
Ex. of correct values:
1
12 345
1 234 567
Ex. of incorrect:
12x
2x1
1237
I have tried the pattern bellow, but it does not work
<input pattern="([0-9]*[ ]*)*"/>
Thanks for your help
try this -
<input pattern="[0-9 ]+"/>
Note: there is a space before ]
in javascript you can get actual number by replacing all " "(spaces) with "" and converting the string to integer

Extracting character sequence containing word

I've got an HTML string containing special character sequences looking like this:
[start_tag attr="value"][/end_tag]
I want to be able to extract one of these sequences containing specific attribute e.g:
[my_image_tag image_id="12345" attr2="..." ...]
and from the above example, I want to extract the whole thing with square brackets but using only one of the attributes and its value in this case - image_id="12345"
I tried using regex but it gives me the whole line whereas I need only the part of the line based on specific value as mentioned above.
Something like this should work:
my_string = '<h1>Heading1</h1>some text soem tex some text [some_tag attrs][/some_tag]some text some text [some_tag image_id="12345"] some text'
search_attrs = %w(image_id foo bar)
found = my_string =~ /(\[[^\]]*(#{search_attrs.join('|')})="[^"\]]*"[^\]]*\])/ && $1
# => "[some_tag image_id=\"12345\"]"
For a specific attribute id and value, you can simplify it like so:
found = my_string =~ /(\[[^\]]* image_id="12345"[^\]]*\])/ && $1
# => "[some_tag image_id=\"12345\"]"
It works by expanding the primary capture group to everything you're looking for.
However, this assumes you only need to extract one such attribute.
It also assumes that you don't care if the string crosses through any HTML tag boundaries. If you cared about that, then you'd need to first hash out the legal boundaries using an HTML parser, then search within those results.

How to get particular string from my table?

My table column contains following sample data:
/Users/abct2/Library/Application Support/iPhone Simulator/4.3/Applications/FD301781-D39F-469E-A604-8164CC9A4493/Library/Caches/List3-ROHAN TEST1/word_306:24:50.jpg
Now, I want to extract any text which comes after /Library/Caches/ (that is List3-ROHAN TEST1/word_306:24:50.jpg). How do I write the select statment for this?
Just FYI, text which is preceding /Library/Caches/ can have any number of slashes.
Please let me know..
Thanks!
If you can assume that "/Library/Caches/" only appears in one position then you can do this:
SUBSTR (text, INSTR(text,'/Library/Caches/')+16)
There are 16 characters in '/Library/Caches/', so the part you want starts 16 characters after the position of '/Library/Caches/' in text.

How can I preserve leading white space in PDF export of reporting services

I have some leagacy reporting data which is accessed from SSRS via an xml web service data source. The service returns one big field containing formatted plain text.
I've been able to preserve white space in the output by replacing space chars with a non-breaking space, however, when exporting to PDF leading white space is not preserved on lines that do not begin with a visible character. So a report that should render like this:
Report Title
Name Sales
Bob 100.00
Wendy 199.50
Is rendered like this:
Report Title (leading white space stripped on this line)
Name Sales (intra-line white space is preserved)
Bob 100.00
Wendy 199.50
I've not been able to find any solution other than prefixing each line with a character which I really don't want to do.
Using SQL 2005 SP3
I googled and googled the answer to this question. Many answers included changing spaces to Chr(20) or Chr(160). I found a simple solution that seems to work.
If your leading spaces come from a tab stop replace "/t" with actual spaces, 5 or so
string newString = oldString.Replace("/t"," ")
In the expression field for the textbox I found that simply adding a null "Chr(0)" at the beginning of the string preserves the leading spaces.
Example:
=Chr(0) & "My Text"
Have you tried non-breaking spaces of the ASCII variety?
=Replace(Fields!Report.Value, " ", chr(160))
I use chr(160) to keep phone numbers together (12 345 6789). In your case you may want to only replace leading spaces.
You can use padding property of the textbox containing the text. Padding on the left can be increased to add space that does not get stripped on output.
I have used this work around:
In the Textbox properties select the alignment tab.
In the Padding option section edit the right or left padding(wherever you need to add space).
If you need to conditionally indent the text you can use the expression as well.