Why is TrimStart not recognised in VisualStudio for ASP.NET? - asp.net

I whant to use TrimStart for my string value like this: How to remove all zeros from string's beginning?
But TrimStart syntax is not recognise in VisualStudio. How to corectly generate it?
my code:
string str = parameters.Internal;
string s = str;
string no_start_zeros = s.TrimStart('0');

At the top of your .CS file do you have: using system; the string.TrimStart(); method is found in the system namespace, which is contained inside mscorlib.dll - you can also try referencing mscorlib.dll directly.

TrimStart() function is used to Removes all leading occurrences of a set of characters specified in an array from the current String object.
when visual studio version you are using ? as far as I know trimStart() support in almost all version from 1.1 to 4.5
check out below snippet for more detail
string szInput = "000YTHLKJH";
string output = szInput.TrimStart('0');
//output will be : YTHLKJH
Hope it helps

Related

Save text file with code page UTF-8 in Axapta 3.0

How do I make a text file with code page UTF-8 in Axapta 3.0?
I cannot use
myFile = new CommaIo(myFileName, 'W', 65001);
as we can in newer versions of Axapta. In Axapta 3.0 new CommaIo only have the first two parameters.
I've not worked in 3.0, but I have a few ideas for you that might send you the right way.
1) Do you have CommaTextIo or TextIo? Those are the objects where you can specify a code page.
2) Look in the AOT and see if you have a macro called #File, and inside if you have #utf8Format(65001), use the X-Ref (or Ctrl+F) to find other places in the system that use it. Then you can see how they might accomplish UTF-8
3) See if you can combine CommaIo with some .NET code, or just manually generated a CSV. Perhaps generate your CSV and write it, then read it and re-write it using a method like below (from MetadataXMLGenerator job):
void write(str _directory, str _name, str _text)
{
str path;
;
_text = System.Text.RegularExpressions.Regex::Replace(_text, '\n', '\r\n');
if (!System.IO.Directory::Exists(_directory))
{
System.IO.Directory::CreateDirectory(_directory);
}
path = System.IO.Path::Combine(_directory, _name);
System.IO.File::WriteAllText(path, _text, System.Text.Encoding::get_UTF8());
}

typeof equivalent of .NET for ABL Progress Openedge

I have added System.Messaging to my assemblies.xml cause I need to use this in my Progress OpenEdge application. However I ran into a problem.
In C# when assigning:
m.Formatter = new XmlMessageFormatter(new[] { typeof(TrowConfiguration) });
TrowConfiguration myConfiguration = m.Body as TrowConfiguration;
However I now want to do this in ABL. I first used a method to read a string and just passed a CHARACTER EXTENT 1 INITIAL "System.String" to the XmlMessageFormatter object. However I tried changing this to the path of my object, TrowConfiguration, but this doesn't work and gives me an error.
If you're looking for the System.Type reference, use
Progress.Util.TypeHelper:GetType ("<your fully qualified type name>").

Classic ASP getPathName and getName Error

I usually developed website using PHP. But now i have to using ASP Classic because my client already have a website then i have to maintenance the website. i already move all of the website to my new hosting. But there is error on this code :
cPath=getPathName(Server.mappath(Request.ServerVariables("PATH_INFO")))
The error message is :
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'getPathName'
Some error display when call getName code.
Please help me what should i do.
Classic ASP or VBScript do not have equivalent to the PHP getPathName() and getName() functions as far as I can tell.
I wasn't able to understand what's the meaning of getPathName() when it's given a string and actually I don't think it exists, so just have:
cPath = Server.MapPath(Request.ServerVariables("PATH_INFO"))
And the variable will contain the full physical path to the currently executing ASP file.
As for getName() you can write custom function:
Function GetOnlyName(filePath)
Dim slashIndex
slashIndex = InStrRev(filePath, "\")
If slashIndex<1 Then
slashIndex = InStrRev(filePath, "/")
End If
If slashIndex>0 Then
ExtractFileName = Mid(filePath, slashIndex + 1, Len(filePath) - slashIndex + 1)
Else
ExtractFileName = filePath
End If
End Function
Then use it like this:
cName = GetOnlyName(Server.MapPath(Request.ServerVariables("PATH_INFO")))
And the variable will contain only the name of the ASP file.
For the record, to avoid confusing Type Mismatch errors, always put this on top of your scripts:
Option Explicit
Then always declare all your variable using Dim statement, like in the function above. Having this, trying to use getPathName would give "variable undefined" error which is much more meaningful.

Character + is converted to %2B in HTTP Post

I'm adding functionality to a GM script we use here at work, but when trying to post (cross site may I add) to another page, my posting value of CMD is different than what it is on the page.
It's supposed to be Access+My+Account+Info but the value that is posted becomes Access%2BMy%2BAccount%2BInfo.
So I guess my question is: What's escaping my value and how do I make it not escape? And if there's no way to unescape it, does anyone have any ideas of a workaround?
Thanks!
%2B is the code for a +. You (or whatever framework you're using) should already be decoding the POST data server-side...
Just a quick remark: If you want to decode a path segment, you can use UriUtils (spring framework):
#Test
public void decodeUriPathSegment() {
String pathSegment = "some_text%2B"; // encoded path segment
String decodedText = UriUtils.decode(pathSegment, "UTF-8");
System.out.println(decodedText);
assertEquals("some_text+", decodedText);
}
Uri path segments are different from HTML escape chars (see list). Here is an example:
#Test
public void decodeHTMLEscape() {
String someString = "some_text+";
String stringJsoup = org.jsoup.parser.Parser.unescapeEntities(someString, false);
String stringApacheCommons = StringEscapeUtils.unescapeHtml4(someString);
String stringSpring = htmlUnescape(someString);
assertEquals("some_text+", stringJsoup);
assertEquals("some_text+", stringApacheCommons);
assertEquals("some_text+", stringSpring);
}
/data/v50.0/query?q=SELECT Id from Case
This worked for me. Give space instead of '+'

converting a string to a constant string

I have the following code...
Const ToAddress As String = username.Text & "#gmail.com"
which sets to ToAddress to be used in on my Net.Mail.MailMessage
that is to be created with the following constructor
Dim mm As New Net.Mail.MailMessage(username.Text, ToAddress)
which takes in a string and a constant string. But I get an error here
Const ToAddress As String = **username.Text** & "#gmail.com"
that says : constant expression required
how to use mailmessage
username.text is variable, you wont be able to create a const
you can always create a function that would do validation on the username.text
public function ToAddress(byval _username as string) as MailAddress
'
'validation here for _username
'
return new MailAddress(_username & "#gmail.com")
end function
That is not how a Const should be used. See the first line here. "a constant is a special kind of variable whose value cannot be altered during program execution"
Edit: See Fredou's answer for the correct syntax.
VB.NET and C# are not C. Constant modifier is just used for constants whose values are known at the time of compilation.
Remember that a constant is a value that is compiled as a literal into the assembly by the compiler. This is why you cannot define constants as an expression because the compiler cannot evaluate the expression at compilation time.
When you define a constant the compiler takes the value of that constant and replaces all uses of the constant in your source with the literal value. In your example I don't see any reason why you would need to define your string as Const since the method receiving the string will have no way of determining if the string was a Const at compilation time.
Rather than using a Const, specifically, if you just want the "constant" behavior for the life of an instance of your class, try:
ReadOnly ToAddress As String = username.Text & "#gmail.com"
Thank you for your assistance. I closed visual studio and restarted it and now it's sending mail works fine. Seems like VS has a bug...

Resources