删除字符串中的空格 [英] Deleting blanks in a string

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

问题描述

大家好。


我有一个应用程序从一个数组中的套接字接收来自

一定大小的消息。由于数组大小可能比收到的消息长,

数组末尾有空白字符。


我使用System.Text.Encoding。 ASCII.GetString方法转换为字符串

并插入数据库中。问题是在数据库中插入的空格也是b $ b。如何在插入

数据库之前删除空白?


-


问候,


迭戈F.

解决方案

Diego F.写道:


我有一个应用程序从一个特定大小的

数组中的套接字接收消息。由于数组大小可能比收到的

消息长,所以数组的末尾有空白字符。


我使用System.Text.Encoding。 ASCII.GetString方法转换为

字符串并插入数据库。问题是在数据库中

也会插入空白。如何在数据库中插入

之前删除空格?



String.Trim()


Andrew


你好Andrew,你好迭戈,


>我使用System.Text.Encoding.ASCII.GetString方法转换为
字符串并插入数据库中。问题是在数据库中也插入了空白。如何在插入数据库之前删除空白?



String.Trim()



修剪将仅删除前导和尾随空白。如果你想删除

任何空白,无论它在哪个位置,请使用替换


Dim s As String =" 12345 67890

s =替换(s,,,)


Nach dem Aufruf von替换帽子的den Wert 1234567890"。


BesteGrü?e,


Martin


Martin H 。写道:


> Hello Andrew,你好迭戈,
Trim只会删除前导空格和尾随空格。如果你想要删除任何空白,无论它在哪个位置,请使用替换
而不是



Diego F.写道:


我有一个应用程序从一个特定大小的

数组中的套接字接收消息。由于数组大小可能比收到的

消息长,因此数组的末尾有空白字符。



OP特别指的是数组的* end * ...


Andrew


Hi all.

I have an application that receives a message from a socket in an array from
a certain size. As the array size may be longer that the message received,
the end of the array has blank characters.

I use the System.Text.Encoding.ASCII.GetString method to convert to string
and insert in a database. The problem is that in the database the blanks are
inserted as well. How can I remove the blanks before inserting in the
database?

--

Regards,

Diego F.

解决方案

Diego F. wrote:

I have an application that receives a message from a socket in an
array from a certain size. As the array size may be longer that the
message received, the end of the array has blank characters.

I use the System.Text.Encoding.ASCII.GetString method to convert to
string and insert in a database. The problem is that in the database
the blanks are inserted as well. How can I remove the blanks before
inserting in the database?

String.Trim()

Andrew


Hello Andrew, hello Diego,

>I use the System.Text.Encoding.ASCII.GetString method to convert to
string and insert in a database. The problem is that in the database
the blanks are inserted as well. How can I remove the blanks before
inserting in the database?


String.Trim()

Trim will only remove leading and trailing blanks. If you want to remove
any blank no matter at which position it is, use Replace instead

Dim s As String = " 12345 67890 "
s = Replace (s, " ", "")

Nach dem Aufruf von Replace hat s den Wert "1234567890".

Beste Grü?e,

Martin


Martin H. wrote:

>Hello Andrew, hello Diego,
Trim will only remove leading and trailing blanks. If you want to
remove any blank no matter at which position it is, use Replace
instead

Diego F. wrote:

I have an application that receives a message from a socket in an
array from a certain size. As the array size may be longer that the
message received, the end of the array has blank characters.

The OP did specifically refer to the *end* of the array...

Andrew


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

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