Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement iPod text Separator with VBS

Shulou Source: shulou.com Published: 2022-06-03 06:48:21 10月04日 Update

This article will explain in detail how to achieve iPod text splitter in VBS. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

So during the summer vacation, I wrote this short and pithy script version of the splitter. The biggest benefit of the script version can be DIY by the user.

I won't say much about the specific situation, but you can refer to the question of txt coding, iPod text splitter.

This is just a description of how to use it. Drag and drop the Txt file you need to split and send it directly to this script and ok it.

The following is the script code, directly copied and saved as a vbs file on it!

Good Luck!

The copy code is as follows:

'

'Description: Text division for iPod text reading.

'because of iPod can not display text length

'more than 4KB in each file, we have to split

'the bigger one.

'And iPod intrenal use Unicode, so this script

'can also tranfrom the character coding.

'Author: Guoyafeng@jspi.edu.cn

Last Modified: 2008-8-31 11:05:13

'

Option Explicit

Sub OpenDir (Dir)

Dim WShell,CmdString

Set WShell = CreateObject ("WScript.Shell")

CmdString = "Explorer.exe" & Dir

WShell.Run CmdString,1,True

End Sub

Function FormatStrNum (iNum)

Const Mode = "0000"

Dim sNum

SNum = CStr (iNum)

FormatStrNum = Left (Mode,Len (Mode)-Len (sNum)) & sNum

End Function

Function IIf (test,a,b)

If test = True Then IIf = an Else IIf = b

End Function

Function GetDragDropFile

If WScript.Arguments.Count = 0 Then MsgBox "Please drag and drop the Txt file that needs to be split onto this script!"

WScript.Quit

Else

Dim fso

Set fso = CreateObject ("Scripting.FileSystemObject")

If (fso.FileExists (WScript.Arguments (0) Then

GetDragDropFile = WScript.Arguments (0)

Set fso = Nothing

Else

Set fso = Nothing

MsgBox "cannot find file" & WScript.Arguments (0)

WScript.Quit

End If

End If

End Function

Const ForReading = 1

Const ForWriting = 2

Const ForAppending = 8

Const TristateTrue =-1

Const TristateUseDefault=-2

Const TristateFalse=0

Dim ToWrite

Dim Index

Dim fso

Dim src

Dim dst

Dim TextSize

Dim MaxTextLength

Dim SourceFile

Dim DestinationFile

Dim BaseName

Dim OutFolderPath

Dim IsUnicode

Dim regEx,patrn

'*

'Splited text size.

TextSize = 4'KB

IsUnicode = True

'*

MaxTextLength = 1024 * TextSize / 2-1

Patrn = "(\ r\ n\ r\ n) + | (+)"

Set regEx = New RegExp

RegEx.Pattern = patrn

RegEx.IgnoreCase = True

RegEx.Global = True

Set fso = CreateObject ("Scripting.FileSystemObject")

BaseName = fso.GetBaseName (GetDragDropFile)

OutFolderPath = fso.BuildPath (fso.GetParentFolderName (GetDragDropFile), _

BaseName)

Set src = fso.OpenTextFile (GetDragDropFile, ForReading,False,_

TristateUseDefault)

If Not fso.FolderExists (OutFolderPath) Then

Fso.CreateFolder OutFolderPath

End If

Index = 1

While (src.AtEndOfStream True)

ToWrite = src.Read (MaxTextLength)

DestinationFile = fso.BuildPath (OutFolderPath,BaseName & _

FormatStrNum (Index) & ".txt")

Set dst=fso.OpenTextFile (DestinationFile,ForWriting,True,IIf (IsUnicode,TristateTrue,TristateUseDefault))

Dim SlimText

SlimText = regEx.Replace (ToWrite, "")

Dst.Write SlimText

Dst.Close

Set dst = Nothing

Index = Index + 1

Wend

Src.Close

Set src = Nothing

Set fso = Nothing

Set regEx = Nothing

OpenDir OutFolderPath

On "VBS how to achieve iPod text splitter" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Scripts splitters files text code articles more references good practical maximum short concise usage users content benefits situations articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Apple Shulou Technology Shulou Information