string builder append format in vb.net - datatable

having string builder recieved values from the datatable . datatable contains the column named
as ename and contain the values like
abc
abc
abc
in stringbuilder stored this value in the following format abcabcabc.
code
Do While (i < dt.Rows.Count)
sb.Append(dt.Rows(i)("ename").ToString)
i = (i + 1)
Loop
Expected output abc,abc,abc .how to do this?

Related

Determine column on which invoke custom function

I am trying to invoke a function on an added column that will concatenate two columns. The catch is that I can't use the column name shorthand as I use dynamic parameters using strings to determine the column name.
Therefore the result is that I get a column as a List multiplied per row rather than the concatenated value for the specific row as intended
(func as text) =>
let
Source = Excel.CurrentWorkbook(){[Name="DataTBL"]}[Content],
\\This is the string extraction process for the parameter
funcTrig = Text.Start(func, 1),
columnA = "" & Text.BetweenDelimiters(func,"_","_") & "",
columnB = "" & Text.AfterDelimiter(func,"_",1) & "",
\\converting the string to column data
Convert2ColA = Table.Column(Source,columnA),
Convert2ColB = Table.Column(Source,columnB),
\\function to concatanate column A value at a specific row with column B value at the same row.
concat= StraightForward(Convert2ColA ,Convert2ColB)
in
concat
I have outlined with remarks the process and desired results, In the added picture I have pulled out the result of "Convert2ColA" what is the desired result will be 1999 in row one and so on.

How do I get a valid date format from a string using Pig

I have a source record that represents a date like this:
20151104
when I used Pig to load the source file, I defined the record like this:
data_raw = LOAD '/user/hue/myfile.csv' USING PigStorage(',') AS
(date:datetime)
Then use the following code to push it to a new format:
data_values = FOREACH data_raw GENERATE ToString(date, 'yyyyMMdd') AS
date
When I dump the variable out, I get:
(201511040101)
Where is the 0101 coming from?
The input is not in ISO date and time formats.
Change input date to 20151104 to 2015-11-04, you will be able to see the expected result.
Ref :
http://www.w3.org/TR/NOTE-datetime
https://pig.apache.org/docs/r0.11.1/func.html#datetime-functions
If you can read the input as String and if its in expected format then you need not do any conversion, if not make use of DateTime Functions to achieve the same.
Update : If you have Date as String in one format and you like to convert it to any other format then if you have to work with ToDate() and ToString() methods.
N.B : Return type of ToDate is DateTime object and that of ToString is String
http://pig.apache.org/docs/r0.12.0/func.html#to-date
http://pig.apache.org/docs/r0.12.0/func.html#to-string
Input :
20151104
PigScript :
A = LOAD 'date_input' USING PigStorage(',') AS (my_date:chararray);
B = FOREACH A GENERATE ToDate(my_date, 'yyyyMMdd') AS my_date;
C = FOREACH B GENERATE ToString(my_date,'yyyy-MM-dd') AS my_date;
Output :
DUMP B :
(2015-11-04T00:00:00.000-08:00)
DUMP C :
(2015-11-04)

How to split a column which has data in XML form to different rows of new Database as KEY VALUE in TALEND

In old DB i have a data in one column as
<ADDRESS>
<CITY>ABC</CITY>
<STATE>PQR</SERVICE>
</ADDRESS>
In my new DB i want this data to be stored in KEY VALUE fashion like:
USER_ID KEY VALUE
1 CITY ABC
1 STATE PQR
Someone please help me how to migrate this kind of data using TALEND tool.
Design job like below.
tOracleInput---tExtractXMLFiled---output.
tOracleInput component you can select XML column and make datatype as String.
tExtractXmlFiled component pass this XML column as " XML Filed" and set the Loop xpath Expression as "/ADDRESS"
Add new two Columns in output Schema of tExtractXmlFiled for city & STATE
Set XPath Query in Mapping for city "/ADDRESS/CITY" and for STATE "/ADDRESS/STATE"
Now you have both the values in output.
See the image for more details.
as I explain in your previous post you can follow the same approach for making Key value pair.
how-to-split-one-row-in-different-rows-in-talend
Or you can use tUnpivot component as you did here.
As you said source data has Special character then use below expression to replace it.
Steps: after oracle input add tMap and use this code for replacement of special symbol
row24.XMLField.replaceAll("&", "<![CDATA["+"&"+"]]>")
once that is done execute the job and see the result it should work.
I'd use tJavaFlex.
Component Settings:
tJavaFlex schema:
In the begin part, use
String input = ((String)globalMap.get("row2.xmlField")); // get the xml Fields value
String firstTag = input.substring(input.indexOf("<")+1,input.indexOf(">"));
input = input.replace("<"+firstTag+">","").replace("</"+firstTag+">","");
int tagCount = input.length() - input.replace("</", "<").length();
int closeTagFinish = -1;
for (int i = 0; i<tagCount ; i++) {
in the main part, parse the XML tag name and value, and have the output schema contain that 2 additional column. MAIN part will be like:
/*set up the output columns */
output.user_id = ((String)globalMap.get("row2.user_id"));
output.user_first_name = ((String)globalMap.get("row2.user_first_name"));
output.user_last_name = ((String)globalMap.get("row2.user_last_name"));
Then we can calculate the key-value pairs for the XML, without knowing the KEY values.
/*calculate columns out of XML */
int openTagStart = input.indexOf("<",closeTagFinish+1);
int openTagFinish = input.indexOf(">",openTagStart);
int closeTagStart = input.indexOf("<",openTagFinish);
closeTagFinish = input.indexOf(">",closeTagStart);
output.xmlKey = input.substring(openTagStart+1,openTagFinish);
output.xmlValue = input.substring(openTagFinish+1,closeTagStart);
tJavaFlex End part:
}
Output looks like:
.-------+---------------+--------------+------+--------.
| tLogRow_2 |
|=------+---------------+--------------+------+-------=|
|user_id|user_first_name|user_last_name|xmlKey|xmlValue|
|=------+---------------+--------------+------+-------=|
|1 |foo |bar |CITY |ABC |
|1 |foo |bar |STATE |PQR |
'-------+---------------+--------------+------+--------'

Insert formatted values as currency type while using EPPlus

I am using format:
type ="$###,###,##0.00"
for currency and assigning the format type to the worksheet cells
eg.
wrkSheet.Cells[0].Style.Numberformat.Format = formatType;
But this is inserted as text type in excel.
I want this to be inserted as Currency or Number in order to continue to do analysis on the values inserted (sort, sum etc).
Currently as it is text type validations do not hold correct.
Is there any way to force the type in which the formatted values can be inserted?
Your formatting is correct. You needs to covert values to its native types
Use this code, it should work:
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("Sales list - ");
worksheet.Cells[1, 1].Style.Numberformat.Format = "$###,###,##0.00";
worksheet.Cells[1, 1].Value =Convert.ToDecimal(24558.4780);
package.SaveAs(new FileInfo(path));
}
Indices start from 1 in Excel.
This code
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("Sales list - ");
worksheet.Cells[1, 1].Style.Numberformat.Format = "$###,###,##0.00";
worksheet.Cells[1, 1].Value = 24558.4780;
package.SaveAs(new FileInfo(path));
}
produces $24 558,48 for me

How to insert a new line into database and read value onto my webgrid in razor MVC 3

I am using Razor, MVC3 with Poco entities.
While inserting into the database I am using Enviroment.NewLine as a seperator between two texts.
oldValues += " Name = '" + oldName.Name + "'" + Environment.NewLine ;
oldValues += " Age = '" + oldName.Age + "'" + Environment.NewLine ;
I am then assigning this oldValues string object to one of my columns in the database.
But when I am reading this value onto my webgrid, the formatting does not appear as expected.
What could be the problem here ?
Please suggest me some methods, I have also tried appending
<br />
tags too.
Expected Output in one of my webgrid column:
Old Values are
Name = Yasser
Age = 24
and New Values are
Name = Yasser R
Age =25
Actual Output in one of my webgrid column:
Old Values are Name = Yasser Age = 24 and New Values are Name = Yasser R Age =25
That's the behavior of HTML. You can wrap your text with <pre>Your String Here</pre> and it should display the text as you're expecting it.
With some help from Paul, I have managed to solve this problem
here is what I am using now
logGrid.Column(header: "Message", columnName: "Message", format: #<pre>#item.Message </pre>),

Resources