字符串对齐问题 [英] String Alignment problem

查看:97
本文介绍了字符串对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,


我的问题与使用.Net从数据库写一个文本文件

有关。以特定的字符串格式。

我有一个带有表格的数据集,假设在这个表格中有

三个字段。

- 代码

- 说明

- 金额


在编写文本文件时,我在for循环中使用 -


String.Format(" {0,10} {1,40} {2,-10}",DS.Table(0).Row(i)

(" Code")。ToString(),DS.Table(0).Row(i)(" Description")。ToString(),

DS.Table(0) .Row(i)(Amount)。ToString())
但问题与对齐有关。数据来自

格式如下:


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000

我希望数据符合正确的对齐格式。


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000

所以任何人都知道这个问题的解决方案,请和请

立即回复,紧急。


Rahul

Friends,

My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields.
- Code
- Description
- Amount

At the time of writing a text file I use in a for loop -

String.Format("{0,10}{1, 40} {2,-10}", DS.Table(0).Row(i)
("Code").ToString(), DS.Table(0).Row(i)("Description").ToString(),
DS.Table(0).Row(i)("Amount").ToString())
But the problem is related to the alignment. Data comes like in
following format:

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000
I want Data comes in following proper alignment format.

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000
So anybody knows the solutions of this problem, please and please
reply imediately, its urgent.

Rahul

推荐答案

6月4日上午10点08分,Rahul< verma.car ... @ gmail.comwrote:
On Jun 4, 10:08 am, Rahul <verma.car...@gmail.comwrote:

朋友,


我的问题与使用.Net从数据库写入文本文件

有关。以特定的字符串格式。

我有一个带有表格的数据集,假设在这个表格中有

三个字段。

- 代码

- 说明

- 金额


在编写文本文件时,我在for循环中使用 -


String.Format(" {0,10} {1,40} {2,-10}",DS.Table(0).Row(i)

(" Code")。ToString(),DS.Table(0).Row(i)(" Description")。ToString(),

DS.Table(0) .Row(i)(Amount)。ToString())


但问题与对齐有关。数据来自

格式如下:


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000


我希望数据符合正确的对齐格式。


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000


所以任何人都知道解决方案这个问题,请和请

立即回复,紧急。


Rahul
Friends,

My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields.
- Code
- Description
- Amount

At the time of writing a text file I use in a for loop -

String.Format("{0,10}{1, 40} {2,-10}", DS.Table(0).Row(i)
("Code").ToString(), DS.Table(0).Row(i)("Description").ToString(),
DS.Table(0).Row(i)("Amount").ToString())

But the problem is related to the alignment. Data comes like in
following format:

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000

I want Data comes in following proper alignment format.

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000

So anybody knows the solutions of this problem, please and please
reply imediately, its urgent.

Rahul



对于格式化选项,您的输出将如下:

01Code 01Desc2000

而不是

01Code 01Desc 2000


此外,某些字符串可能无法进行格式化如果

数据集中任何字符串的长度超过了你在格式选项中指定的宽度。

你能告诉我你的数据吗?真实数据?

For the formatting option that you have your output will be like:
01Code 01Desc2000
and not
01Code 01Desc 2000

Also, some of the strings may not be getting formatted properly if
length of any string in your dataset exceeds the width that you
specify in the format option.
Can you show me with your real data?


6月4日上午10点38分,GeezerButler< kurtr ... @ gmail.comwrote:
On Jun 4, 10:38 am, GeezerButler <kurtr...@gmail.comwrote:

6月4日上午10点08分,Rahul< verma.car ... @ gmail.com写道:


On Jun 4, 10:08 am, Rahul <verma.car...@gmail.comwrote:



朋友,
Friends,


我的问题与从数据库写入文本文件

使用相关。净。以特定的字符串格式。

我有一个带有表格的数据集,假设在这个表格中有

三个字段。

- 代码

- 说明

- 金额
My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields.
- Code
- Description
- Amount


在编写文本文件时我使用在for循环中 -
At the time of writing a text file I use in a for loop -


String.Format(" {0,10} {1,40} {2,-10}", DS.Table(0).Row(i)

(" Code")。ToString(),DS.Table(0).Row(i)(" Description")。ToString( ),

DS.Table(0).Row(i)(Amount)。ToString())
String.Format("{0,10}{1, 40} {2,-10}", DS.Table(0).Row(i)
("Code").ToString(), DS.Table(0).Row(i)("Description").ToString(),
DS.Table(0).Row(i)("Amount").ToString())


但问题与对齐有关。数据类似于

格式:
But the problem is related to the alignment. Data comes like in
following format:


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000
01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000


我想要数据遵循正确的对齐格式。
I want Data comes in following proper alignment format.


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000
01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000


所以任何人都知道这个问题的解决方案,请和

立即回复,其中紧急。
So anybody knows the solutions of this problem, please and please
reply imediately, its urgent.


Rahul
Rahul



对于格式化选项,您的输出将如下:

01Code 01Desc2000

而不是

01Code 01Desc 2000


此外,一些字符串可能如果

数据集中任何字符串的长度超过了你在格式选项中指定的宽度,那么就不能正确格式化。

你能不能告诉我你的真实数据? - 隐藏引用的文字 -


- 显示引用的文字 -


For the formatting option that you have your output will be like:
01Code 01Desc2000
and not
01Code 01Desc 2000

Also, some of the strings may not be getting formatted properly if
length of any string in your dataset exceeds the width that you
specify in the format option.
Can you show me with your real data?- Hide quoted text -

- Show quoted text -



感谢回复

我已经在空间放置'' - ''以便更好地理解。

这是针对Northwind数据库,产品表

真实数据是:


alice mutton ---------------------------- alice mutton


茴香糖浆---------------------------茴香糖浆


波士顿蟹肉------------------------波士顿蟹肉


卡门贝尔皮埃罗-----------------------卡门贝尔皮埃罗


carnarvon老虎------------------------ carnarvon老虎


chai ----- ------------------------------- chai


chang ----- ------------------------------ chang


绿松石----- ------------------- chartreuse verte


厨师安东的cajun调料---------- --chef anton'的cajun调味品


厨师安东'的浓汤混合------------------厨师安东'' s gumbo mix


chocolade ------------------------------- chocolade


c?te de blaye --------------------------- c?te de blaye


escargots de bourgogne ------------------ escargots de bourgogne


filo mix ---- ---------------------------- filo mix


flotemysost ------- ---------------------- flotemysost


geitost -------------- ------------------- geitost


genen shouyu ---------------------------- genen shouyu


gnocchi di nonna alice-- ---------------- gnocchi di nonna alice


gorgonzola telino ---------------- ------- gorgonzola telino


奶奶的波森莓传播------------奶奶的波森莓蔓延


gravad lax ------------------------------ gravad lax

$ b $bararanáfantástica----------------------guaranaáfantástica

gudbrandsdalsost -------- ---------------- gudbrandsdalsost


gula malacca ------------------- --------- gula malacca


gumb?r gummib?rchen --------------------- gumb?r gummib?rchen


gustaf'的kn?ckebr?d --------------------- gustaf' 's kn?ckebr?d


ikura ------------------------------ ----- ikura


inlagd sill ----------------------------- inlagd sill


怡保咖啡-----------------------------怡保咖啡


jack' s new england clam chowder --------- jack'的新英格兰蛤蜊

杂烩


konbu ------- ---------------------------- konbu


lakkalik ?? ri ----- ----------------------- lakkalik ?? ri


笑的伐木工人啤酒-------- -------笑的伐木工人啤酒


长寿豆腐-------------------------- - 长寿豆腐


路易斯安那火热的辣椒酱--------路易斯安那火热的辣椒




路易斯安那热辣的秋葵---------------路易斯安那州热辣的秋葵


manjimup干苹果--------- ---------- manjimup干苹果


mascarpone fabioli ---------------------- mascarpone fabioli


maxilaku -------------------------------- maxilaku


mishi kobe niku ------------------------- mishi kobe niku


mozzarella di giovanni ------------------ mozzarella di giovanni


nord-ost matjeshering -------- - - - - - -没有rd-ost matjeshering


northwoods酸果蔓酱--------------北方蔓越莓酱


nunuca nu ?-nougat-creme ----------------- nunuca nu?-nougat-creme


原始法兰克福grüne所以?e --- ------原版法兰克福grüne

如此?e


内陆啤酒---------------- -----------内陆啤酒

$ b $bpatéchinois----------------------- -----patéchinois


pavlova ------------------------------ --- pavlova


珀斯馅饼---------------------------珀斯馅饼

queso cabrales -------------------------- queso cabrales


queso manchego la pastora --------------- queso manchego la pastora


raclette courdavault ------------ -------- raclette courdavault


馄饨angelo --------------------------馄饨angelo


rh?nbr?u klosterbier -------------------- rh?nbr?u klosterbier


r?d kaviar ----------- ------------------- r?d kaviar


rogede sild ------------- ---------------- rogede sild


r?ssle sauerkraut ----------------- ------ r?ssle sauerkraut


sasquatch ale -------------------------- -sasquatch ale


schoggi schokolade ---------------------- schoggi schokolade


scottish longbreads --------------------- scottish longbreads


新加坡福建炒面mee ------ -----新加坡人福建炒面吧


先生罗德尼的果酱------------------先生罗德尼's橘子酱


先生罗德尼的烤饼---------------------先生罗德尼的烤饼


sirop d''érable-------------------------- sirop d''érable


spegesild ------------------------------- spegesild


steeleye stout -------------------------- steeleye stout


tarte au sucre ---- ---------------------- tarte au sucre


teatime choco晚饼干--------------下午茶时间巧克力饼干

$ b $bthüringerrostbratwurst----------------- thüringerrostbratwurst


豆腐----------------------------------- -tofu

$ b $btourtière-------------------------------tourtière

tunnbr?d -------------------------------- tunnbr?d

叔叔鲍勃'的有机干梨---------叔叔鲍勃'的有机干燥




valkoinen suklaa ------------------------ valkoinen suklaa


vegie-spread --- ------------------------- vegie-spread


wimmers gute semmelkn?del ----- ---------- wimmers gute semmelkn?del


zaanse koeken --------------------- ------ zaanse koeken

Rahul

thanks for reply
I have put ''-'' on the place of space for better understanding.
This comes for Northwind database, product table
the real data is :

alice mutton----------------------------alice mutton

aniseed syrup---------------------------aniseed syrup

boston crab meat------------------------boston crab meat

camembert pierrot-----------------------camembert pierrot

carnarvon tigers------------------------carnarvon tigers

chai------------------------------------chai

chang-----------------------------------chang

chartreuse verte------------------------chartreuse verte

chef anton''s cajun seasoning------------chef anton''s cajun seasoning

chef anton''s gumbo mix------------------chef anton''s gumbo mix

chocolade-------------------------------chocolade

c?te de blaye---------------------------c?te de blaye

escargots de bourgogne------------------escargots de bourgogne

filo mix--------------------------------filo mix

flotemysost-----------------------------flotemysost

geitost---------------------------------geitost

genen shouyu----------------------------genen shouyu

gnocchi di nonna alice------------------gnocchi di nonna alice

gorgonzola telino-----------------------gorgonzola telino

grandma''s boysenberry spread------------grandma''s boysenberry spread

gravad lax------------------------------gravad lax

guaraná fantástica----------------------guaraná fantástica

gudbrandsdalsost------------------------gudbrandsdalsost

gula malacca----------------------------gula malacca

gumb?r gummib?rchen---------------------gumb?r gummib?rchen

gustaf''s kn?ckebr?d---------------------gustaf''s kn?ckebr?d

ikura-----------------------------------ikura

inlagd sill-----------------------------inlagd sill

ipoh coffee-----------------------------ipoh coffee

jack''s new england clam chowder---------jack''s new england clam
chowder

konbu-----------------------------------konbu

lakkalik??ri----------------------------lakkalik??ri

laughing lumberjack lager---------------laughing lumberjack lager

longlife tofu---------------------------longlife tofu

louisiana fiery hot pepper sauce--------louisiana fiery hot pepper
sauce

louisiana hot spiced okra---------------louisiana hot spiced okra

manjimup dried apples-------------------manjimup dried apples

mascarpone fabioli----------------------mascarpone fabioli

maxilaku--------------------------------maxilaku

mishi kobe niku-------------------------mishi kobe niku

mozzarella di giovanni------------------mozzarella di giovanni

nord-ost matjeshering-------------------nord-ost matjeshering

northwoods cranberry sauce--------------northwoods cranberry sauce

nunuca nu?-nougat-creme-----------------nunuca nu?-nougat-creme

original frankfurter grüne so?e---------original frankfurter grüne
so?e

outback lager---------------------------outback lager

paté chinois----------------------------paté chinois

pavlova---------------------------------pavlova

perth pasties---------------------------perth pasties

queso cabrales--------------------------queso cabrales

queso manchego la pastora---------------queso manchego la pastora

raclette courdavault--------------------raclette courdavault

ravioli angelo--------------------------ravioli angelo

rh?nbr?u klosterbier--------------------rh?nbr?u klosterbier

r?d kaviar------------------------------r?d kaviar

rogede sild-----------------------------rogede sild

r?ssle sauerkraut-----------------------r?ssle sauerkraut

sasquatch ale---------------------------sasquatch ale

schoggi schokolade----------------------schoggi schokolade

scottish longbreads---------------------scottish longbreads

singaporean hokkien fried mee-----------singaporean hokkien fried mee

sir rodney''s marmalade------------------sir rodney''s marmalade

sir rodney''s scones---------------------sir rodney''s scones

sirop d''érable--------------------------sirop d''érable

spegesild-------------------------------spegesild

steeleye stout--------------------------steeleye stout

tarte au sucre--------------------------tarte au sucre

teatime chocolate biscuits--------------teatime chocolate biscuits

thüringer rostbratwurst-----------------thüringer rostbratwurst

tofu------------------------------------tofu

tourtière-------------------------------tourtière

tunnbr?d--------------------------------tunnbr?d

uncle bob''s organic dried pears---------uncle bob''s organic dried
pears

valkoinen suklaa------------------------valkoinen suklaa

vegie-spread----------------------------vegie-spread

wimmers gute semmelkn?del---------------wimmers gute semmelkn?del

zaanse koeken---------------------------zaanse koeken
Rahul


您应该将输出组织到一个包含3列的表中。最简单的方法

是使用GridView控件数据绑定到你的数据集。


-

Eliyahu Goldin,

软件开发人员&顾问

Microsoft MVP [ASP.NET]
http: //msmvps.com/blogs/egoldin
http://usableasp.net

Rahul < ve ********** @ gmail.comwrote in message

news:11 ******************** **@j4g2000prf.googlegro ups.com ...
You should organize the output into a table with 3 columns. The easiest way
is to use GridView control databound to your dataset.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Rahul" <ve**********@gmail.comwrote in message
news:11**********************@j4g2000prf.googlegro ups.com...

朋友,


我的问题与写文本有关来自数据库的文件

使用.Net。以特定的字符串格式。

我有一个带有表格的数据集,假设在这个表格中有

三个字段。

- 代码

- 说明

- 金额


在编写文本文件时,我在for循环中使用 -


String.Format(" {0,10} {1,40} {2,-10}",DS.Table(0).Row(i)

(" Code")。ToString(),DS.Table(0).Row(i)(" Description")。ToString(),

DS.Table(0) .Row(i)(Amount)。ToString())


但问题与对齐有关。数据来自

格式如下:


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000


我希望数据符合正确的对齐格式。


01Code 01Desc 2000

02Code 02Desc 3000

03CodeABC 03Desc 4000

04xyz 04Desc 5000


所以任何人都知道解决方案这个问题,请和请

立即回复,紧急。


Rahul
Friends,

My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields.
- Code
- Description
- Amount

At the time of writing a text file I use in a for loop -

String.Format("{0,10}{1, 40} {2,-10}", DS.Table(0).Row(i)
("Code").ToString(), DS.Table(0).Row(i)("Description").ToString(),
DS.Table(0).Row(i)("Amount").ToString())
But the problem is related to the alignment. Data comes like in
following format:

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000
I want Data comes in following proper alignment format.

01Code 01Desc 2000
02Code 02Desc 3000
03CodeABC 03Desc 4000
04xyz 04Desc 5000
So anybody knows the solutions of this problem, please and please
reply imediately, its urgent.

Rahul



这篇关于字符串对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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