获取列名称和左键区域零 [英] Get Column Name and Left Pad zeroes

查看:74
本文介绍了获取列名称和左键区域零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

 您能否请求下面的要求,

 Can you please help with the requirement below,

在SSIS脚本组件中我传递所有字段一张桌子。每当有一个名为'abc'或'bcd'的列

In SSIS Script component I am passing all fields of a table . Whenever there is a column named 'abc' or 'bcd'

我想要从右边填充8个零和子串8个字符。源col是十进制的,但在转换后它应该是字符串。

I want to left pad 8 zeroes and substring 8 characters from right. The source col is decimal but after transformation it should be string.

这是我的代码。能帮助您达到这个要求吗。

this is my code. can you please help to achieve this requirement.







推荐答案

因此,给定一个十进制值,您希望得到最右边的8个字符,然后确保左边有8个?这似乎是一个非常奇怪的要求。

So, given a decimal value you want to get the rightmost 8 characters and then ensure there are 8 0s on the left? That seems like a really odd requirement.

string someValue = "123456789.98765432";

//Get the rightmost 8 characters
var rightmostEight = someValue.Substring(someValue.Length - 8, 8);

//Pad with 8 zeroes on the left - since you are getting the righmost 8 this means the entire result is 16 digits
var final = rightmostEight.PadLeft(16, '0');


如果这是一个十进制值并且您需要精度,那么您需要先执行该操作,然后向左填充,然后使用所需的多个零来获得所需的宽度。 br />

If this is a decimal value and you want precision then you'll need to do that first and then pad left with however many zeroes you need to get to the width you want.


这篇关于获取列名称和左键区域零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆