Stream C# 截取的问题

dsw123129 2009-12-14 07:25:39
Stream stream = httpClient.DownloadData("http://sbcx.saic.gov.cn/trade/pictureservlet3?" + imageUrl[1].Replace("&", "&"));

int streamLength = (int)stream.Length;
byte[] bte = new byte[streamLength];
stream.Read(bte, 6, streamLength-13);
//设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
stream.Close();

//////////////////////////////////////////////////
我想把stream前6个字节去掉后7个字节去掉
然后读出来!想直接从stream里面截取!
...全文
274 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyalex 2009-12-17
  • 打赏
  • 举报
回复
无耻
sensenstudy 2009-12-15
  • 打赏
  • 举报
回复
Stream stream = httpClient.DownloadData("http://sbcx.saic.gov.cn/trade/pictureservlet3?" + imageUrl[1].Replace("&", "&"));

int streamLength = (int)stream.Length;
byte[] bte = new byte[streamLength];
steam.Position = 6;
stream.Read(bte, 0, streamLength-13);
//设置当前流的位置为流的开始
//stream.Seek(0, SeekOrigin.Begin);
stream.Close();
-------------------------------------------------------
完美!
Jave.Lin 2009-12-15
  • 打赏
  • 举报
回复
mark
dsw123129 2009-12-15
  • 打赏
  • 举报
回复
Stream stream = httpClient.DownloadData("http://sbcx.saic.gov.cn/trade/pictureservlet3?" + imageUrl[1].Replace("&", "&"));

int streamLength = (int)stream.Length;
byte[] bte = new byte[streamLength];
steam.Position = 6;
stream.Read(bte, 0, streamLength-13);
//设置当前流的位置为流的开始
//stream.Seek(0, SeekOrigin.Begin);
stream.Close();

你这样试试,我觉得应该可以!
andyalex 2009-12-14
  • 打赏
  • 举报
回复
当然,ms.Read(bte, 0,(int)(ms.Length-13));
这里读的时候要注意,小的话这样是可以的,但是如果大文件话,最好每次读一小段,在循环里做判断就可以了
andyalex 2009-12-14
  • 打赏
  • 举报
回复
根据你需要的,稍微改一下,

string str = "abcdef123456789abc1234567";
byte[] bs2 = System.Text.Encoding.UTF8.GetBytes(str);
MemoryStream ms = new MemoryStream(bs2);
byte[] bte = new byte[ms.Length - 13];
ms.Seek(6, SeekOrigin.Begin);// 从第7个开始读取
ms.Read(bte, 0,(int)(ms.Length-13));
string str1 = System.Text.Encoding.ASCII.GetString(bte, 0, bte.Length);
Console.WriteLine(str1);

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧