VB.NET - VBScript - Insert text into the middle of a string

Asked By Hazeus Barbarius
18-Nov-08 01: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  Solution

18-Nov-08 02: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  use replace method for that

18-Nov-08 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  try this link

19-Nov-08 03:56 AM

http://www.entisoft.com/estools/Index_I.HTML#Insert http://www.entisoft.com/estools/Index_S.HTML#String Function
http://www.entisoft.com/estools/StringManipulations.HTML 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 http://www.entisoft.com/estools/StringManipulations_StrIns.HTML subroutine, except that this is a function which returns the result instead of modifying an argument.
Example:
    InsertString("123456", "NEW", 3) = "12NEW3456"
See also:
    http://www.entisoft.com/estools/StringManipulations_OverlayString.HTML Function
http://www.entisoft.com/estools/StringManipulations_DeleteString.HTML Function
http://www.entisoft.com/estools/StringManipulations_StrIns.HTML 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

Create New Account
help
Difference between vb and vb.net Hai, I want to know about the main difference between vb and vb.net. • The greatest change in VB6 and VB.NET is of runtime environment. VB6 used the VB-Runtime while VB.NET uses the .Net Common Language Runtime (.Net CLR). The CLR is much better designed and
types? (B) What is concept of Boxing and Unboxing ? (B) What is the difference between VB.NET and C#? (I) what is the difference between System exceptions and Application exceptions? (I)What are different properties provided by Object-oriented systems? (B) How can we achieve inheritance in VB.NET? (I) what are abstract classes? (B) What is a Interface? (A) What is difference between prevent a class from overriding? (I) what is the use of “Must inherit” keyword in VB.NET? (I) Do interface have accessibility modifier. (A) What are similarities between Class and structure? (A between Class and structure’s? (B) What does virtual keyword mean? (B) What are shared (VB.NET) / Static(C#) variables? (B) What is Dispose method in .NET? (B) What is the use
Differences for vb.net and c# with Example Dear all Differences for vb.net and c# with Example., plz give the solutions Thanks to all Hi See the bellow comparission :: This comparission is with syntax and example. . . Comments VB.NET 'Single line only Rem Single line only C# / / Single line / * Multiple line * / / / / XML comments on single line / * * XML comments on multiple lines * / Program Structure VB.NET Imports System Namespace MyNameSpace Class HelloWorld 'Entry point which delegates to C-style main Private
diffrence what 's diif b / w vb.net & c#.net refer the link, it explan u Syntax Differences and Managed and Unmanaged code in earlier versions. You have lot of articles to find out the differences b / w VB.NET & C#.NET depending on various aspects. Iam providing a few, which were discussed in different aspects. Go through them. http: / / support.microsoft.com / kb / 308470 some key syntactical differences between VB.NET (version 2) and C#. http: / / www.harding.edu / fmccown / vbnet_csharp_comparison.html Choosing between C# and VB.NET: http: / / www.dnjonline.com / article.aspx?ID = mar05_vbvscsharp Complete Comparison for VB.NET and C
Diff between C# and VB.Net I know 60 to 70 percentage of C#. In Some Interviews asked me. Do you know vb.net like that. First of all what is the difference between C# and VB.Net There is very little difference. The are both languages that target the Common Language Runtime The only real difference is the syntax that you use. VB.NET tends to be more verbose. This is the most debatable issue in .NET community and