Hi Mickey,
I have converted your original VB code into C#, like this:
private string sqltext(string sdata)
{
string strtemp;
int intx=sdata.IndexOf("'",1);
if(intx>0)
{
strtemp=sdata.Substring(1,intx);
strtemp=strtemp+"'"+sdata.Substring(intx+1);
int inty=strtemp.IndexOf("'",intx+2);
while(inty!=0)
{
string strtemp2=strtemp.Substring(1,inty);
strtemp=strtemp2+"'"+strtemp.Substring(inty+1);
inty=strtemp.IndexOf("'",inty+2);
}
}
else
{
strtemp=sdata;
}
return "'"+strtemp.Trim()+"'";
}
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Mickey Swanson" <sw*****@dixie-net.com>
| References: <#l*************@TK2MSFTNGP11.phx.gbl>
<Hk**************@cpmsftngxa06.phx.gbl>
| Subject: Re: vb6 to C#
| Date: Tue, 18 Nov 2003 19:48:29 -0600
| Lines: 158
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#6**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: r164h149.dixie-net.com 64.89.164.149
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!cpmsftn gxa10.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gb l
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:200376
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the help this is what I came up with. If you would please look
| over it and let me know if this is done correctly or if you think
something
| should be changed.
|
|
| private string SqlText(string text)
| {
| int start;
| int at;
|
| at = 0;
| start = 0;
|
| while((start < text.Length) && (at > -1))
| {
| at = text.IndexOf("'", start);
| if (at == -1) break;
| at = at+1;
| text = text.Insert(at, "'");
| start = at+1;
| }
|
| return "'" + text + "'";
| }
|
|
|
| Thanks for your help,
|
| Mickey Swanson
|
|
|
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:Hk**************@cpmsftngxa06.phx.gbl...
| >
| > Hi Mickey,
| >
| > Thanks for posting in this group.
| > In .Net, VB.net and C# all use the .Net class library to do the same
| thing,
| > the different is only the syntax of invoking the class library.
| > For your string parse problem, you can refer to the System.String class
in
| > Net class library.
| > For example, your "intX = InStr(1, sData, "'")" statement can be
replaced
| > with:
| > System.String sData="......";
| > intX=sData.IndexOf("'",1);
| >
| > While, your "strTemp = Mid$(sData, 1, intX)" can be changed into:
| > System.String sData="......";
| > strTemp=sData.SubString(1,intX);
| >
| > For more information of the string operation in .Net, please refer to
the
| > String class description and member, here is the link:
| >
|
http://msdn.microsoft.com/library/en...StringClassTop
| > ic.asp
| >
| > If you still have anything unclear, please feel free to tell me.
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! -
www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Mickey Swanson" <sw*****@dixie-net.com>
| > | Subject: vb6 to C#
| > | Date: Sun, 16 Nov 2003 18:20:20 -0600
| > | Lines: 65
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#l*************@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: r166h97.dixie-net.com 64.89.166.97
| > | Path:
| >
|
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP11.
| > phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:199732
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I need some help converting the following to c#.
| > | I'm new to the dotnet stuff so any help or pointers would be
| appreciated.
| > | I'm having trouble finding the replacements for InStr and Mid$
| > |
| > |
| > |
| > |
| > |
| > | Public Function SQLText(ByVal sData As String) As String
| > |
| > |
| > |
| > | Dim strTemp As String
| > |
| > | Dim StrTemp2 As String
| > |
| > | Dim intX As Integer
| > |
| > | Dim intY As Integer
| > |
| > |
| > |
| > | intX = InStr(1, sData, "'")
| > |
| > |
| > |
| > | If intX > 0 Then
| > |
| > | strTemp = Mid$(sData, 1, intX)
| > |
| > | strTemp = strTemp & "'" & Mid$(sData, intX + 1)
| > |
| > |
| > |
| > | intY = InStr(intX + 2, strTemp, "'")
| > |
| > | Do Until intY = 0
| > |
| > | StrTemp2 = Mid$(strTemp, 1, intY)
| > |
| > | strTemp = StrTemp2 & "'" & Mid$(strTemp, intY + 1)
| > |
| > | intY = InStr(intY + 2, strTemp, "'")
| > |
| > | Loop
| > |
| > | Else
| > |
| > | strTemp = sData
| > |
| > | End If
| > |
| > |
| > |
| > | SQLText = "'" & Trim$(strTemp) & "'"
| > |
| > |
| > |
| > | End Function
| > |
| > |
| > |
| > | Mickey Swason
| > |
| > |
| > |
| >
|
|
|