How to select the last elements in a string
Hi Guys
I am using UART RS232 protocol and i need to calculate the check sum. My data came in decimal and in the end it must be doubles to manipulate it. So my problem is, for example, the sum of all elemants is in decimal 1742 and in hex is 6CE and i wont only the last two elemants, CE that corresponds to 206 that is the result of my checksum. Can anyone help me?
Thanks
Solved!
Go to Solution.
Attachments:
String last elements.vi 9 KB
Thanks Syrpimp
My data came from HMI in decimal like the example that i show above. Each cell is a value. You used an array, but i think that i can't use it because it must be done automatically and the data field have variable length.
The UART protocol frame has a start frame field that corresponds to two ‘{‘ characters and an end frame field that corresponds to two ‘}’. Additionally, besides the data field, that has variable length, it has a byte that corresponds to the command type and another that is the checksum. The following table illustrates the protocol.
Bytes considered in checksum
Command Data
Start Frame
Cmd
(hex)
Data0
Data1
Data2
Data3
Data4
Data5
Data6
Data…
CHK SUM
End Frame
1 Byte CHK SUM (sum of all data bytes truncated to 1 byte)
Fig. 1 UART communication protocol template
I receive data like this:
123
123
160
54
111
103
110
108
107
109
108
108
100
100
100
100
0
0
1
4
5
0
0
0
0
0
0
7
96
1
0
0
0
0
0
10
51
1
0
0
51
1
1
23
12
0
206
125
125
I'm trying explain my doubt the best way i can and i thank you all.
Similar Messages
-
How to delete the last element of a collection without iterating it?
how to delete the last element of a collection without iterating it?
To add to jverd's reply, even if you could determine the last element, in some collections it is not guaranteed to always be the same.
From HashSet:
It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. -
How to get the last element of a structure in a textfield in DesignStudio
Hello,
how can I get the last element of a structure within a bex query?
Within the structure we are working with dates that dynamically are buiId (input date - offsets for several months).
I have to show the last value in a single textfield within DesignStudio.
Regards
FrankHi Frank,
in DS 1.3 you can use forEach function to get the last element of BEx structure (or n-th element in general using if condition)
var array = DS_CROSSTAB1.getMembers("DHGY5D6XEFO1K45SB00BXFH7A",10);
var lastMember="";
array.forEach(function(element, index) {
lastMember = element.text;
TEXT_1.setText("Last structure element: "+lastMember); -
How to remove only the last element of spreadsheet string
I use path to string option to store image path into database and while retrieving the string is again converted into path but it gives out an error as the output of array to spreadsheet string gives out a tab at the end which is unable for the IMAQ read file to recognise.but when i use the path of the image directly into IMAQ readfile the image is opened . so how to remove the tab only at the end of output of the spreadsheet string(whose length can vary)? I have also attached my program with this.
Attachments:
retrieve_images_from_DB.vi 65 KB
file_path_to_db_(images).vi 40 KB
create_table_for_images.vi 45 KBindhu wrote:
> Thanks for your reply!
> But my problem is to remove only the last element(which is a tab or an
> alphabet) from a spreadsheet string of any length.
If you just want to remove the last character of a string just use the
String Size function reduce the result by one and wire it together with
the string to the Split String function.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
How to delete the last char in a String?
i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?
Try it in this way
String MyString = "ABCDEF";
MyString = MyString.substring(0,MyString.length()-1); -
How to find the last element of a byte array
Dear all,
I have a byte array with a max lenght of 1024*50 bytes. In that array I store the bytes read from a file. How can I find where the array ends (i.e. which is the last valid element of the byte array)?
Thank you for your help.
Best Regards,
JIMI want to send files over TCP connection using BufferedOutputStreams and BufferedInputStreams. The first side (e.g. the client) sends a file (e.g mp3 file or jpeg image) to the server using the code
public void sendFile(Socket s, String FileName) throws Exception
BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(FileName));
int len = 0;
while ( (len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
in.close();
out.flush();
}(The client does not close the BufferedOutputStream out because other files will be sent afterwards)
Then, the server receives the file using the code:
public void receiveFile(Socket s, String FileName) throws Exception
OutputStream out = new BufferedOutputStream(new FileOutputStream(FileName));
InputStream in = new BufferedInputStream(s.getInputStream());
int len = 0;
while ( (len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
break;
out.flush();
out.close();
}(likewise the InputStream in is not closed for the same reasons).
In order the server to receive the file and stop reading the BufferedInputStream, I will have to make some modifications to this part of the code,
while ( (len = in.read(buffer)) > 0)so as to know when the whole file has been received.
Thus, even if I send the length of each file, I will not be able to read it. Could you please recommend me a solution? -
How to SELECT the last autonumber??
In Access, i have an autonumber column...How do i get the last record (last autonumber) out?
ThanksIn Access, i have an autonumber column...How do i get
the last record (last autonumber) out?
ThanksTry this:
while ( ! rsresult_a.EOF){
//do here the select last record
select row_name
.... etc}
//display the result
<%= rsresult_a%>
Good luck! -
How to Select the last price of parts
Hi Gents,
I have below table
TranNum | TranDate | PartNum | Price
1 | 1/1/15 | 111 | 5
2 | 1/5/15 | 212 | 7
3 | 1/7/15 | 111 | 4.5
4 | 1/8/15 | 212 | 6
5 | 1/9/15 | 212 | 5
I need to create new view to select last price per part.
TranDate | PartNum | Price
1/7/15 | 111 | 4.5
1/9/15 | 212 | 5
Thanks in advance.
Nothing is impossibleSomething like this will work as well...
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
GO
CREATE TABLE #temp (
TranNum INT PRIMARY KEY,
TranDate date,
PartNum int,
Price decimal(10,2)
CREATE UNIQUE NONCLUSTERED INDEX ix_Temp_PartNum_TranDate ON #temp (
PartNum,
TranDate
INCLUDE (
Price
WITH (DATA_COMPRESSION = PAGE)
INSERT INTO #temp (TranNum,TranDate,PartNum,Price)
VALUES
(1 ,'1/1/15 ',111,5),
(2 ,'1/5/15 ',212,7),
(3 ,'1/7/15 ',111,4.5),
(4 ,'1/8/15 ',212,6),
(5 ,'1/9/15 ',212,5)
SELECT
t1.TranNum,
t1.TranDate,
t1.PartNum,
t1.Price
FROM
#temp t1
WHERE EXISTS (
SELECT 1
FROM #temp t2
WHERE t1.PartNum = t2.PartNum
GROUP BY t2.PartNum
HAVING t1.TranDate = MAX(t2.TranDate)
Please note... Without any indexing on PartNum & TranDate, my solution will perform about the same as Martin's solution (currently the fasted of the supplied solutions).
Adding the following index, however, will show that the "EXISTS" solution can dramatically out perform the "NOT EXISTS" solution...
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
GO
CREATE TABLE #temp (
TranNum INT PRIMARY KEY,
TranDate date,
PartNum int,
Price decimal(10,2)
CREATE UNIQUE NONCLUSTERED INDEX ix_Temp_PartNum_TranDate ON #temp (
PartNum,
TranDate
INCLUDE (
Price
WITH (DATA_COMPRESSION = PAGE)
INSERT INTO #temp (TranNum,TranDate,PartNum,Price)
VALUES
(1 ,'1/1/15 ',111,5),
(2 ,'1/5/15 ',212,7),
(3 ,'1/7/15 ',111,4.5),
(4 ,'1/8/15 ',212,6),
(5 ,'1/9/15 ',212,5)
SELECT
t1.TranNum,
t1.TranDate,
t1.PartNum,
t1.Price
FROM
#temp t1
WHERE EXISTS (
SELECT 1
FROM #temp t2
WHERE t1.PartNum = t2.PartNum
GROUP BY t2.PartNum
HAVING t1.TranDate = MAX(t2.TranDate)
HTH,
Jason
Jason Long -
Select the last saved records in a table
I all
I have this struct in a table
create table INT_OBJ
IDOBJ NUMBER(15) not null,
IDERP NUMBER(15),
IDE NUMBER(15),
CPO VARCHAR2(20),
VLR VARCHAR2(2500),
VLRC VARCHAR2(2500)
How to Select the last saved records in a table. I think usea a temp table for put the last row read and begin to read in the next row.
The table is reading each four hours.Theoretically it can be done with ORA_ROWSCN and enabled ROWDEPENDENCIES, but there are so many nuances, so only adding column for ordering is right.
Regards,
Sayan Malakshinov -
The last character of a string
How to judge the last char of a string is " ?
if (s.endsWith("""))or
if (s.endsWith("/""))bet
you just copied and pasted what the OP had written
and quickly put that
backslash in, hit post without previewing first just
to make me look like
a slow old sod! It's not fair ;-)
kind regards,
JosNope, I used the Alt-[numeric code] combinations to manually type each character. Cut-n-paste is for wimps, and actually typing single-stroke keys is for milquetoasts.
Alt-[numeric code] is for real men ;-) -
How can I select the last 2 chars of a string
Hello all,
I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
Thanks.hi,
try this:
public class StringTest {
public static void main(String args[]) {
StringTest obj = new StringTest();
obj.same();
void same() {
String rain = new String("Rain");
String plain = new String("Plain");
int rainLength = rain.length();
int plainLength = plain.length();
if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
System.out.println("same");
else {
System.out.println("different");
}you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars. -
How to get the last day according to fiscal period input in selection scree
Hello expert
how to get the last day of fiscal period input.
the fiscal period inculdes 1-16
when fiscal period is greater than 12, only calculate the last day of 12nd month
your solution will be apprecaited, FM existing?
thank you
KevinHi,
when you give a particular date in any month
the following fm will give you the last date of that month
here you can give
R_FDATE-HIGH as 01 and month as the period you wnat and year for current year
concatenates '01' month year into r_fdate-high separated by '.'.
then it will give g_ltdt for that month and year which wil be the last date of that month
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = R_FDATE-HIGH
IMPORTING
LAST_DAY_OF_MONTH = G_LTDT
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
thanks & regards,
Venkatesh -
How to get the last day of the week?
Hii
i can get the calender week number for any given date using
SELECT to_char(to_date('04/04/2011','MM/DD/YYYY'),'WW') FROM dual
can any body tell me, how to get the last day of that week ?
and the answer should be 04/08/2011(8th april )
thanks
San
Edited by: sandeep9 on Apr 4, 2011 3:50 AMHi, San,
Here's one way:
WITH sample_data AS
SELECT DATE '2011-04-04' AS dt
FROM dual
SELECT dt
, TO_CHAR (dt, 'WW') AS week_num
, NEXT_DAY ( dt - 1
, TO_CHAR ( TRUNC (dt, 'YEAR') - 1
, 'Day'
) AS end_o_week
FROM sample_data;Another way is to use date arrithmetic:
WITH sample_data AS
SELECT DATE '2011-04-09' AS dt
FROM dual
SELECT dt
, TO_CHAR (dt, 'WW') AS week_num
, TRUNC (dt, 'YEAR')
+ (7 * CEIL ( (dt - (TRUNC (dt, 'YEAR') - 1))
/ 7
- 1 AS using_date_arithmetic
FROM sample_data; -
got a new wireless connection for my mac and cannot figure out how to delete the last connection service I had. Everytime I shut the computer, the network goes back to the other one. I cannot find the file ANYWHERE
Under Network Preferences, select the WiFi
click on "Advanced..." button
Select the network you want to delete from the list and click on "-"
Click "Ok"
Click "Apply"
Well done ;-)
You may also want to delete the wireless key from Keychain.
Open Keychain, seach for the old wifi network name, slect it and click delete -
HELP! How te retrieve the last row in MYSQL database using Servlet!
Hi ,
I am new servlets. I am trying to retireve the last row id inserted using the servlet.
Could someone show me a working sample code on how to retrieve the last record inserted?
Thanks
MY CODE
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class demo_gr extends HttpServlet {
//***** Servlet access to data base
public void doPost (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
String url = "jdbc:mysql://sql2.njit.edu/ki3_proj";
String param1 = req.getParameter("param1");
PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
String semail, sfname, slname, rfname, rlname, remail, message;
int cardType;
sfname = req.getParameter("sfname");
slname = req.getParameter("slname");
rfname = req.getParameter("rfname");
rlname = req.getParameter("rlname");
semail = req.getParameter("semail");
remail = req.getParameter("remail");
message = req.getParameter("message");
//cardType = req.getParameter("cardType");
cardType = Integer.parseInt(req.getParameter("cardType"));
out.println(" param1 " + param1 + "\n");
String query = "SELECT * FROM greeting_db "
+ "WHERE id =" + param1 + "";
String query2 ="INSERT INTO greeting_db (sfname, slname ,semail , rfname , rlname , remail , message , cardType ,sentdate ,vieweddate) values('";
query2 = query2 + sfname +"','"+ slname + "','"+ semail + "','"+ rfname + "','"+ rlname + "','"+ remail + "','"+ message + "','"+ cardType + "',NOW(),NOW())";
//out.println(" query2 " + query2 + "\n");
if (semail.equals("") || sfname.equals("") ||
slname.equals("") || rfname.equals("") ||
rlname.equals("") || remail.equals("") ||
message.equals(""))
out.println("<h3> Please Click the back button and fill in <b>all</b> fields</h3>");
out.close();
return;
String title = "Your Card Has Been Sent";
out.println("<BODY>\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" );
out.println("\n" +
"\n" +
" From " + sfname + ", " + slname + "\n <br> To "
+ rfname + ", " + rlname + "\n <br>Receiver Email " + remail + "\n<br> Your Message "
+ message + "\n<br> <br> :");
if (cardType ==1)
out.println("<IMG SRC=/WEB-INF/images/bentley.jpg>");
else if(cardType ==2) {
out.println("<IMG SRC=/WEB-INF/images/Bugatti.jpg>");
else if(cardType ==3) {
out.println(" <IMG SRC=/WEB-INF/images/castle.jpg>");
else if(cardType ==4) {
out.println(" <IMG SRC=/WEB-INF/images/motocross.jpg>");
else if(cardType ==5) {
out.println(" <IMG SRC=/WEB-INF/images/Mustang.jpg>");
else if(cardType ==6) {
out.println("<IMG SRC=/WEB-INF/images/Mustang.jpg>");
out.println("</BODY></HTML>");
try {
Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection
( url, "*****", "******" );
Statement stmt = con.createStatement ();
stmt.execute (query2);
//String query3 = "SELECT LAST_INSERT_ID()";
//ResultSet rs = stmt.executeQuery (query3);
//int questionID = rs.getInt(1);
System.out.println("Total rows:"+questionID);
stmt.close();
con.close();
} // end try
catch (SQLException ex) {
//PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
while (ex != null) {
out.println ("SQL Exception: " + ex.getMessage ());
ex = ex.getNextException ();
} // end while
} // end catch SQLException
catch (java.lang.Exception ex) {
//PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
out.println ("Exception: " + ex.getMessage ());
} // end doGet
private void printResultSet ( HttpServletResponse resp, ResultSet rs )
throws SQLException {
try {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>jbs jdbc/mysql servlet</title></head>");
out.println("<body>");
out.println("<center><font color=AA0000>");
out.println("<table border='1'>");
int numCols = rs.getMetaData().getColumnCount ();
while ( rs.next() ) {
out.println("<tr>");
for (int i=1; i<=numCols; i++) {
out.print("<td>" + rs.getString(i) + "</td>" );
} // end for
out.println("</tr>");
} // end while
out.println("</table>");
out.println("</font></center>");
out.println("</body>");
out.println("</html>");
out.close();
} // end try
catch ( IOException except) {
} // end catch
} // end returnHTML
} // end jbsJDBCServletI dont know what table names and fields you have but
say you have a table called XYZ which has a primary
key field called keyID.
So in order to get the last row inserted, you could
do something like
Select *
from XYZ
where keyID = (Select MAX(keyID) from XYZ);
Good Luckwhat gubloo said is correct ...But this is all in MS SQL Server I don't know the syntax and key words in MYSQL
This works fine if the emp_id is incremental and of type integer
Query:
select *
from employee e, (select max(emp_id) as emp_id from employee) z
where e.emp_id = z.emp_id
or
select top 1 * from employee order by emp_id descUday
Maybe you are looking for
-
In-Place Hold Combined with In-Place Archiving in Exchange 2013
Hi, In-Place Hold is enabled for a mailbox and set to keep everything indefinitely. The same mailbox has a Retention Policy with a Default Policy Tag set to move everything to an archive mailbox after 2 years. Let's say the user keeps mail in the pr
-
Problem in Rejecting the purchase order release workflow
Hai Friends , I did the purchase order workflow. it will working fine. when a approver refused the release, the intimation need to send to the previous approvers as well as po creator. but there is no method available in the bus2012 fo
-
Weblogic 10.3.5 standalone, jdk 1.8, tls 1.2 settings
Hi, I installed 64 sun jdk on redhat and installed jdeveloper+standalone weblogic server 10.3.5. Then I wanted to enable tls 1.2 and read jdk 1.8 by default uses it. So I installed jdk 8 and changed setDomainEnv.sh and made it use jdk 8. Still it
-
On a whim last weekend I decided to subscribe to a .Mac account and create a website via iWeb. I was in a hurry to publish the site and did so with no problems, so the site is up and running. However, there were a few spelling and formatting mistakes
-
First JavaFX application with long sequential processes
Hi all, I'm working on my first JavaFX application. I have UI elements (view) in place, I have a controller that works properly (with the exception I'll mention below), and I have an model that runs correctly (processes the data properly), but the m