如何将数据插入到字符串中 [英] How to insert data into string

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

问题描述

我有一个数据集 ds ,它被转换为字符串。



ds可能有20列,有时是30列。



现在我想插入一些文本字符串,如果它有更少的列(我不知道有多少列可能存在)



所以任何人都可以告诉我如何在最后将文本插入字符串。



**我不知道字符串的长度。



字符串例如:

I have a dataset ds which is converted to string.

ds may have 20 columns and sometimes 30 columns.

Now I want to insert some text string if it has less columns(which i don't know how many columns mayb exist)

So can anyone tell me how to insert text into string at the end.

**I don't know length the string.

string ex:

2034027436594110044004745638140274381004390000000 000000000000000015000 0000000gdfgdf00000000000 000000000000000000000 000000160510           dfgdfgdfgbdfghdfh8706216710500000000000000000 000000000 0000000000000 00000000000000000000000000000000000000000000                                                                           fghdfhdtgh                                                                                     16051000000000000000000000000000000000000 



<无线电通信/>
我不知道这有多长ytime。

但是我有什么方法可以在不知道长度的情况下在最后添加文字



我尝试了什么:



任何人都可以帮我解决这个问题。

我被困在这里。



I don't know how much length this will be everytime.
But is there any way I can add text at the end without knowing length

What I have tried:

Anyone please help me solve this.
I am stuck here.

推荐答案

Quote:

**我不知道字符串的长度。

**I don't know length the string.

参见 String.Length Property(System) [ ^ ]



学习c#字符串函数!



ds 转换为strong并在之后添加列可能不是一个好主意,但为此,您需要告诉 DS 以及要添加的列。

See String.Length Property (System)[^]

Learn the c# strings functions!

Converting ds to strong and adding columns after may not be a good idea, but for that, you need to tell what is DS and what columns you want to add.


基本上,你不必知道字符串的大小来附加另一个字符串。

有很多方法可以做到这一点:

Basically, you do not have to know the size of a string to append it another string.
There are a bunch of ways to do that:
string a = "a";
string b = "b";
StringBuilder sb = new StringBuilder(a);

string concat1 = a + b;
string concat2 = string.Concat(a, b);
string concat3 = string.Format("{0}{1}", a, b);
string concat4 =


{A} {b};
string concat5 = sb.Append(b).ToString();
"{a}{b}"; string concat5 = sb.Append(b).ToString();



全部 concat 变量将保持相同的值,这将是字符串变量a和b的串联。


All concat variables will hold the same value, which will be the concatenation of both string variables a and b.


这篇关于如何将数据插入到字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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