search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

View Other VB.NET Posts   Ask New Question 
VBScript - Insert text into the middle of a string
Hazeus Barbarius posted at Tuesday, November 18, 2008 1:30 PM

I am reading a text file line by line checking for specific criteria..

Do While objFile.AtEndOfStream <> True
  strCurrentLine = objFile.ReadLine
if InStr(226, strCurrentLine, "7141570", vbTextCompare) = 226 Then

>Checking Column 226 for this text "7141570", when this returns TRUE I want to insert "99" elsewhere on that line (lets say Column 250).  How do I do this?

 


 
  Solution
san san replied to Hazeus Barbarius at Tuesday, November 18, 2008 2:31 PM
Hi

Try try the bellow code.. It might help you out....


  strCurrentLine = objFile.ReadLine
If Not InStr(226, strCurrentLine, "7141570", 1) = 0 Then
  ' appent 99 at last
  strCurrentLine = strCurrentLine && "99"
End If


How it works?
Take a look at the Instr function
InStr([start,]string1,string2[,compare])

start --> Optional. Specifies the starting position for each search. The search begins at the first character position by default. This parameter is required if compare is specified
string1 --> Required. The string to be searched
string2 --> Required. The string expression to search for
compare --> Optional. Specifies the string comparison to use. Default is 0

Can have one of the following values:

0 = vbBinaryCompare - Perform a binary comparison
1 = vbTextCompare - Perform a textual comparison
-----------
Hope it helps
 
  use replace method for that
Web star replied to Hazeus Barbarius at Tuesday, November 18, 2008 11:24 PM

as follows

strCurrentLine = objFile.ReadLine
If Not InStr(226, strCurrentLine, "7141570", 1) = 0 Then
  'here u replace the "7141570" string with "99" as u wnat
  strCurrentLine = strCurrentLine.Replace('7141570','99')
End If

 
try this link
C_A P replied to Hazeus Barbarius at Wednesday, November 19, 2008 3:56 AM

Insert String Function
String Manipulations Class

Public Function InsertString( _
ByVal vDest As Variant _
, ByVal vSource As Variant _
, Optional ByVal vInsertPosition As Variant _
) As Variant

Insert one string into the middle of another string and return the results.
vSource is inserted into vDest before character position vInsertPosition.

Summary: Similar to the StrIns subroutine, except that this is a function which returns the result instead of modifying an argument.
Example:
    InsertString("123456", "NEW", 3) = "12NEW3456"
See also:
    OverlayString Function
DeleteString Function
StrIns Subroutine
Function returns Null if both strings (vDest and vSource) are Null.

vDest: The string into which the other string is to be inserted. vDest defaults to an empty string if it is Null or cannot be fixed up to a String.

vSource: The string which is to be inserted into the other string. vSource defaults to an empty string if it is Null or cannot be fixed up to a String.



http://www.tek-tips.com/viewthread.cfm?qid=929958
http://p2p.wrox.com/topic.asp?TOPIC_ID=75032