文件重写:一号线比变量的最大尺寸更大。解决方法? [英] File rewriting: One line is greater than variable's max size. Workaround?

查看:119
本文介绍了文件重写:一号线比变量的最大尺寸更大。解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个文件来替换一行。
一般来说,这个code正常工作:

I need to replace a single line in a file. Generally, this code works fine:

。(什么这块做没有必要为这个问题的实际细节)

(The actual specifics on what this block is doing is not necessary for this question).

for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %DATA%') do (
    if %%a equ %TargetLine% (
        echo !insert!>>%filepath%cc.tmp
    ) else (
        if [%%b]==[] (echo.>>%filepath%cc.tmp) else (echo %%b>>%filepath%cc.tmp)
    )
)

不幸的是,每一行被分配到一个%%,这就像任何其他变量只能存储8,192个字符的最大长度(感谢d​​benham为tidbid,当属目前使用)。

Unfortunately, each line is assigned to %%a, which like any other variable can only store a maximum length of 8,192 characters (thanks dbenham for that tidbid, comes in use now).

那么,可以怎么做时,行大于8,192个字符(在这种情况下23708)?

So what options do I have when the line is greater than 8,192 characters (23,708 in this case)?

你问前:不,它不能分离到一个新的生产线,这是一个10K JSON阵列连接为Base64 codeD,然后写入到ByteArray

Before you ask: No it cannot be separated to a new line, it is an 10k JSON array encoded in Base64 which is then written into a ByteArray.

我认为走的是使用常规的前pressions的方式,这是正确的假设,或者是有其他解决办法?

I assume that the way to go is using regular expressions, is this the correct assumption, or is there another workaround?

感谢。

推荐答案

您可以用纯批量解决这个问题!

You could solve this with pure batch!

:readLongLine
< longline.tmp (
    for /L %%n in (1 1 20) do set /p part[%%n]=
)

在此您的线分裂成变量部分[1] .. 部分[20]

After this your line is splitted into the variables part[1] .. part[20]

写这你可以使用一个新的文件

Writing this to a new file you could use

:writeLongLine
<nul (
    for /L %%n in (1 1 19) do set /p ".=!part[%%n]!"
    (echo !part[20]!)
) > longLine2.tmp

这篇关于文件重写:一号线比变量的最大尺寸更大。解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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