Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Thursday, March 29, 2012

Newbie: How to compare strings?

Hi,

On my drop down list control, i am trying to set the
DropDownList1.SelectedValue property to the selected string value. In my
example, my DropDownList1 control contains three colors:

- Carlos
- Mike
- Susan

However, if i try to set the DropDownList1.SelectedValue = "carlos"; i get
the following error: "Exception: Specified argument was out of the range of
valid values. Parameter name: carlos." This is b/c "Carlos" != to "carlos".

I realize that i can convert all the drop down list controls values to
uppercase, however, i'd like to keep the names as they are entered by the
user.

Is there anyway to compare these strings, ignoring any differences in
uppercase or lowercase?

Thanks!String.Compare("CARLOS", "carlos", true);

-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hi,
> On my drop down list control, i am trying to set the
> DropDownList1.SelectedValue property to the selected string value. In
> my example, my DropDownList1 control contains three colors:
> - Carlos
> - Mike
> - Susan
> However, if i try to set the DropDownList1.SelectedValue = "carlos"; i
> get the following error: "Exception: Specified argument was out of the
> range of valid values. Parameter name: carlos." This is b/c "Carlos"
> != to "carlos".
> I realize that i can convert all the drop down list controls values to
> uppercase, however, i'd like to keep the names as they are entered by
> the user.
> Is there anyway to compare these strings, ignoring any differences in
> uppercase or lowercase?
> Thanks!

Newbie: How to compare strings?

Hi,
On my drop down list control, i am trying to set the
DropDownList1.SelectedValue property to the selected string value. In my
example, my DropDownList1 control contains three colors:
- Carlos
- Mike
- Susan
However, if i try to set the DropDownList1.SelectedValue = "carlos"; i get
the following error: "Exception: Specified argument was out of the range of
valid values. Parameter name: carlos." This is b/c "Carlos" != to "carlos".
I realize that i can convert all the drop down list controls values to
uppercase, however, i'd like to keep the names as they are entered by the
user.
Is there anyway to compare these strings, ignoring any differences in
uppercase or lowercase?
Thanks!String.Compare("CARLOS", "carlos", true);
-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hi,
> On my drop down list control, i am trying to set the
> DropDownList1.SelectedValue property to the selected string value. In
> my example, my DropDownList1 control contains three colors:
> - Carlos
> - Mike
> - Susan
> However, if i try to set the DropDownList1.SelectedValue = "carlos"; i
> get the following error: "Exception: Specified argument was out of the
> range of valid values. Parameter name: carlos." This is b/c "Carlos"
> != to "carlos".
> I realize that i can convert all the drop down list controls values to
> uppercase, however, i'd like to keep the names as they are entered by
> the user.
> Is there anyway to compare these strings, ignoring any differences in
> uppercase or lowercase?
> Thanks!
>

Saturday, March 24, 2012

Newbie: Webservice String Function question

Why do i get this message when i try to run it as a webservice?
First "Name 'TRIM' is not declared." Then "Name 'REPLACE' is not declared."

This is the code i use:
<%@dotnet.itags.org. WebService language="VB" class="test" %
Imports System
Imports System.Web.Services
Imports System.Xml.Serialization

Public Class test

<WebMethod> Public Function Add(a As Integer, b As Integer) As Integer
Return a + b
End Function

<WebMethod> Public Function WebTrim(a As String) As string
Return TRIM(a)
End Function

<WebMethod> Public Function WebReplace(a As String) As string
Return REPLACE(a, "e", "f")
End Function

End Class

If i run is like a normal web page it works perfect.
I'm using Webmatrix and have reinstalled all met .net components.

Please help me.

Thanx in advancehave you tried the OO way?

return a.Trim()

return a.Replace("e","f")
Thanx for the quick repley but i found wath it is.
This one i missed:
Imports Microsoft.VisualBasic

Thursday, March 22, 2012

Newbie:sending German characters on TCP link

Hi,

I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?

Thanks in advance and regards

NavinOn Feb 27, 7:44 pm, "Navin Mishra" <navin.mis...@.siemens.comwrote:

Quote:

Originally Posted by

Hi,
>
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?
>


This group is for ASP.NET

Regarding your problem

First of all, ensure that the xml is encoded

sXML = "<?xml version=""1.0"" encoding=""windows-1252""?

Quote:

Originally Posted by

>.........."


then set this encoding to the method which send the data.

For example

myWriter = New System.IO.StreamWriter(xmlRequest.GetRequestStream (),
Encoding.GetEncoding(1252))
myWriter.Write(sXML)

I used German code page 1252 here, but you can consider to use utf-8...
Thus wrote Navin,

Quote:

Originally Posted by

Hi,
>
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine.
Now on a German OS, German characters were sent as question mark in
the received string. I guess that's because ASCII encoding was used
and unicode encoding should be used instead.


Absolutely. If not Unicode, then at least some 8 bit encoding like ISO Latin
1.

Quote:

Originally Posted by

But then would byte
ordering(little endian ir big endian) be a problem because the
received TCP stream could be consumed by both a Java and .NET clients
?


No. All UTF-16/32 variants include byte order marks that allow the receiver
to pick up the appropriate byte order, and UTF-8 is the same for both Big
Endian and Little Endian systems.

Quote:

Originally Posted by

What could be done to ensure that the received unicode encoded XML
stream be decoded by both .NET and Java clients ? And, which encoding
.NET class be used utf8, utf32,.. ? Is there a sample anywhere ?


If your XML contains mostly Latin characters, use UTF-8. That'll require
the least bandwidth. You can write an XML document to any stream using either
an XmlWriter or XmlDocument.Save().

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

Newbie:sending German characters on TCP link

Hi,
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?
Thanks in advance and regards
NavinOn Feb 27, 7:44 pm, "Navin Mishra" <navin.mis...@.siemens.com> wrote:
> Hi,
> I've a .NET application that sends XML string as bytes on a TCP
> connection. It had used ASCII encoding so far and everything was fine. Now
> on a German OS, German characters were sent as question mark in the receiv
ed
> string. I guess that's because ASCII encoding was used and unicode encodin
g
> should be used instead. But then would byte ordering(little endian ir big
> endian) be a problem because the received TCP stream could be consumed by
> both a Java and .NET clients ? What could be done to ensure that the
> received unicode encoded XML stream be decoded by both .NET and Java clien
ts
> ? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sampl
e
> anywhere ?
>
This group is for ASP.NET
Regarding your problem
First of all, ensure that the xml is encoded
sXML = "<?xml version=""1.0"" encoding=""windows-1252""?
>.........."
then set this encoding to the method which send the data.
For example
myWriter = New System.IO.StreamWriter(xmlRequest.GetRequestStream(),
Encoding.GetEncoding(1252))
myWriter.Write(sXML)
I used German code page 1252 here, but you can consider to use utf-8...
Thus wrote Navin,

> Hi,
> I've a .NET application that sends XML string as bytes on a TCP
> connection. It had used ASCII encoding so far and everything was fine.
> Now on a German OS, German characters were sent as question mark in
> the received string. I guess that's because ASCII encoding was used
> and unicode encoding should be used instead.
Absolutely. If not Unicode, then at least some 8 bit encoding like ISO Latin
1.

> But then would byte
> ordering(little endian ir big endian) be a problem because the
> received TCP stream could be consumed by both a Java and .NET clients
> ?
No. All UTF-16/32 variants include byte order marks that allow the receiver
to pick up the appropriate byte order, and UTF-8 is the same for both Big
Endian and Little Endian systems.

> What could be done to ensure that the received unicode encoded XML
> stream be decoded by both .NET and Java clients ? And, which encoding
> .NET class be used utf8, utf32,.. ? Is there a sample anywhere ?
If your XML contains mostly Latin characters, use UTF-8. That'll require
the least bandwidth. You can write an XML document to any stream using eithe
r
an XmlWriter or XmlDocument.Save().
Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

Newline Characters

I added a newline to a string using: ControlChars.NewLine

I want to convert all those newlines to "<br>"

i tried:


Replace(myString, cStr(ControlChars.NewLine) , "<br>")

but it had no effect at all. any ideas?I think it is the other way around:


Replace(myString, "<br>", cStr(ControlChars.NewLine))

If you're using VB, don't you have access to the vbCrLf constant? If so you might be able to do

Replace(myString, vbCrLf, "<br>")

or

Replace(myString, Chr(13), "<br>")
Hello,

i always replace my newline with the help ofRegular Expression code like in the following example...

// Remove the newline's and replace them with <br /> tag
Regex inRegex;
inRegex = new Regex("\n", RegexOptions.IgnoreCase);
lblTest.Text = inRegex.Replace(sText, "<br />");
This sample is written in C# but it should be easy to translate to vb.net. If you need further help please post again...

HTH,
thanks guys,

it worked! btw, what does vbcrlf stand for?
vbcrlf --> I believe it is "VisualBasic CarriageReturn and Line Feed"
Or you can use Environment.NewLine no matter what language you are using.

Friday, March 16, 2012

newline within a string

How can I insert a new line character (\n?) within a string in C#, so that when I display the string in some text box the string is displayed in multiple linesHi,

you can use System.Envirnment.NewLine() method to insert newline. Also if you are using Multiline textbox then I think you need to do something like this:


string AllText = TextBox1.Text.Replace(System.Envirnment.NewLine(),"<BR>");


What I am trying to do is

string strnewline;
TextBox1.text=strnewline;

Now I want to define the strnewline such that
TextBox1.text=strnewline;

displays the text in multiple lines. TextBox1 is multilined.

In short, is there any alternative to C-lang "/n " ?
check the code that I gave you it works !!!!