Right now I'm trying to check if the pass is right when reading the file, but the problem is I have a "Pass:" String in front of the pass.
writeFile.WriteLine("Pass: " + Me.txtCPass.Text) ' pass
Me.txtPassword.Text = (GetLine(FILE_NAME, 2))
Not sure how I would just skip over the "Pass: " and just get right to the pass.
Supposing that GetLine returns a string then
Me.txtPassword.Text = GetLine(FILE_NAME, 2).Substring(6)
Substring is a method of the string class. It returns part of the string instance for which is called.
You could pass a starting index and the method returns the remainder.
Or you could also pass a length to force the method to return a defined part inside the instance
Here on MSDN you could find a detailed description
Me.txtPassword.Text = GetLine(FILE_NAME, 2).Substring(6)
Related
Let's take a string var str = "Hello Kotlin". I want to copy first 5 character of str to another variable strHello. I was wondering is there any function of doing this or I have to apply a loop and copy characters one by one.
As Tim commented, there's a substring() method which does exactly this, so you can simply do:
val strHello = str.substring(0, 5)
(The first parameter is the 0-based index of the first character to take; and the second is the index of the character to stop before.)
There are many, many methods available on most of the common types. If you're using an IDE such as IDEA or Eclipse, you should see a list of them pop up after you type str.. (That's one of many good reasons for using an IDE.) Or check the official documentation.
Please use the string.take(n) utility.
More details at
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/take.html
I was using substring in my project, but it gave an exception when the length of the string was smaller than the second index of substring.
val name1 = "This is a very very long name"
// To copy to another string
val name2 = name1.take(5)
println(name1.substring(0..5))
println(name1.substring(0..50)) // Gives EXCEPTION
println(name1.take(5))
println(name1.take(50)) // No EXCEPTION
I am working in an ABAP program and I have a question.
For example in C# when we have a String variable: string name; , and we want this to be filled with some data from a textbox but also add some ohter text.
For example:
string name = "Hello: " + textBox1.text;,
And I want to ask you how can I do this in ABAP ??? How to add text plus the text written from a Parameter type C?
CONCATENATE and the concatenate operator && will do it as answered by Jagger and vwegert. To do it with string expressions, you use the below where name is the screen field or whatever that has the name in it (it doesn't need to be a field-symbol):
greeting = |Hello: { <name> }|.
String expressions are extremely useful as they can be used to build up complex values without declaring extra variables - e.g. they can passed as directly as function module or method parameters without first assigning to a local variable.
You can either use the CONCATENATE keyword or -- in newer releases -- string expressions. Be sure to check the online documentation and sample programs available using the transaction ABAPDOCU, it will save you a ton of seemingly basic questions.
The equivalent operator is &&.
So in your case it would be:
name = 'Hello: ' && textBox1->text.
apologies if I waffle or talk a bit of jibberish but I'm new to velocity, and these forums!
I need to check the contents of a string for a certain character and output the second part of the text if it appears. For example:
set ($string = "This is a long string *** but I only want to output this on my email").
I want to output all text after the 3 Asterisks. I've scoured the forums but cant quite find anything that helps me completely.
Velocity is just a façade for real Java objects, so you have access to all the public methods of the String class, including indexOf and substring. So try something like:
#set ($string = "This is a long string *** but I only want to output this on my email")
#set ($index = $string.indexOf('***'))
#set ($index = $index + 3)
#set ($end = $string.substring($index))
If you have more control over what objects you put in the context, you could add an instance of StringUtils as a helper tool, and then use substringAfter directly.
I am trying to perform a Substring function on a image filename.
The name format is in "images.png".
I tried using Substring it only allow me to indicate the first character till the "n" character to perform the function.
Such that SubString(1,6).
But what I want is to get any character before the ..
For example "images.png":
After the Substring function I should get "images".
You can use LastIndexOf in conjunction with Substring:
myString.Substring(0, myString.LastIndexOf('.'))
Though the Path class has a method that will do this in a strongly typed manner, whether the passed in path has directories or not:
Path.GetFileNameWithoutExtension("images.png")
How about using the Path class.
Path.GetFileNameWithoutExtension("filename.png");
In general for such string manipulations you can use:
mystring.Split("."c)(0)
But specifically for getting a filename without extension, it's best to use this method:
System.IO.Path.GetFileNameWithoutExtension
Dim fileName As String = "images.png"
fileName = IO.Path.GetFileNameWithoutExtension(fileName)
Debug.WriteLine(fileName)
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
string s = "images.png";
Console.WriteLine(s.Substring(0, s.IndexOf(".")));
Im just wondering if it is possible to put a variable in a pattern match in Lua. Like something similar to the following:
var = "hello"
pattern = string.match(datasource, "(var)%s(a%+)")
The reason I need to do this is because the variable "var" will change periodically. (it will be in a loop)
Cheers in advance
Lua doesn't handle string interpolation inside of the quotes. Instead, you'll need to concatenate the parts with the var as a var reference and the rest as quote strings.
"("..var..")%s(a%+)" starts with a "(" as a string literal, concatenates the variable, then finishes off the rest of the string with a string literal.
Use "("..var..")%s(a%+)" instead.
I needed the same thing I think, a variable in a pattern match, but the above solution didn't work for me. I'm posting my solution in case it helps someone, didn't find anything else on the net like it.
I read a ': ' delimited file (name: tel) and want to search by name in the file and have the name and telephone number as answer.
local FileToSearch = h:read'*a' -- Read all the file
var = io.read() -- ask the name
string.gmatch(FileToSearch, ''..var..': '..'%d+') -- search for name, concatenate with number